ruby-on-rails - 如何在 Ruby on Rails 6 中将 rich_text_area 与 simple_form 一起使用?

标签 ruby-on-rails activerecord simple-form ruby-on-rails-6 actiontext

目前 simple_form 不支持带有 rich_text_area 输入字段的 ruby​​ on rails 6 action_text。 所以目前我的输入字段在 posts/_form.html.haml 中看起来像这样:

= f.label :description
= f.rich_text_area :description
= f.error :description, class: 'text-danger'

如何让它像= f.input :description一样工作并拥有富文本区域?

最佳答案

在 app/inputs/rich_text_area_input.rb 中创建一个文件:

class RichTextAreaInput < SimpleForm::Inputs::Base
  def input_html_classes
    super.push('trix-content')
  end

  def input(wrapper_options = nil)
    merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)

    @builder.rich_text_area(attribute_name, merged_input_options)
  end
end

在 application.scss 中:

//simple_form input for rich_text_area hight
trix-editor.form-control {
  height: auto;
}

现在在 posts/_form.html.haml 中你可以这样做:

= f.input :description, as: :rich_text_area

希望在某个时候 simple_form 必须将其添加到 master

来源 1:https://github.com/heartcombo/simple_form/issues/1638

来源 2:https://github.com/heartcombo/simple_form/pull/1646

关于ruby-on-rails - 如何在 Ruby on Rails 6 中将 rich_text_area 与 simple_form 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61639069/

相关文章:

ruby-on-rails - 编辑 :How to send payments to users every month?

ruby-on-rails - Rails 5 actioncable 卡住服务器

ruby-on-rails - SQL查询(Postgres)正常工作,但不能通过ActiveRecord

ruby-on-rails - 带参数绑定(bind)的 ActiveRecord 选择

ruby-on-rails - 具有简单形式的未定义方法路径

ruby-on-rails - rails map.resources with has_many :through doesn't work?

ruby-on-rails - 如何解决nil :NilClass errror in Rails 4?

ruby-on-rails - 带有 reject_if 的 accepts_nested_attributes_for 的自定义属性版本

ruby-on-rails - 如何在 simple_form 中生成取消按钮?

ruby-on-rails - Rails simple_form gem 正在为预填充的输入添加绿色边框