要在不使用webpack的情况下使用ActionText,可以按照以下步骤进行操作:
gem 'actiontext'
运行bundle install
安装ActionText。
运行以下命令生成ActionText的迁移文件:
rails action_text:install
rails db:migrate
config/application.rb
中添加ActionText的配置:config.autoload_paths += %W(#{config.root}/app/models/rich_text)
has_rich_text
方法,例如在Post
模型中:class Post < ApplicationRecord
has_rich_text :content
end
trix-editor
和trix-editor-container
标签来创建富文本编辑器,例如:
content_tag
方法来渲染内容,例如:<%= content_tag :div, post.content %>
这样就可以在不使用webpack的情况下使用ActionText了。