首先,确保在Gemfile文件中添加了Action Text的引用:
gem 'actiontext', require: 'action_text'
然后,在配置文件config/application.rb中设置Action Text的引擎:
config.generators do |g|
g.template_engine :erb
g.test_framework :test_unit, fixture: false
g.integration_tool :rspec
g.system_tests :minitest
g.scaffold_stylesheet false
g.stylesheets false
g.javascripts false
g.helper false
g.channel assets: false
g.assets false
g.helper_specs false
g.view_specs false
g.fixture_replacement :factory_bot, dir: "test/factories"
g.assets = false
g.helper = false
g.jbuilder = false
g.action_text
end
接下来,在具体使用时,确保正确调用Action Text的trix_editor
和trix_attachment
方法。例如,在表单中使用Action Text:
<%= form_with(model: post) do |form| %>
<%= form.label :content %>
<%= form.rich_text_area :content %>
<% end %>