如何在Ruby on Rails 6中使用simple_form的rich_text_area?

问题描述 投票:0回答:1

目前simple_form不支持ruby on rails 6的action_text与rich_text_area输入字段。所以目前我的输入字段在 posts_form.html.haml 中是这样的。

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

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

ruby-on-rails activerecord simple-form ruby-on-rails-6 actiontext
1个回答
2
投票

在appinputs中创建一个文件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能把它添加到主文件中。

来源1: https:/github.comheartcombosimple_formissues1638。

来源2: https:/github.comheartcombosimple_formpull1646。

© www.soinside.com 2019 - 2024. All rights reserved.