如何在 Rails 6 上将 rich_text_area 与 Ruby 中的 simple_form 一起使用?
How to use rich_text_area with simple_form in Ruby on Rails 6?
目前 simple_form 不支持 rails 6 action_text 上的 ruby 和 rich_text_area 输入字段。
所以目前我的输入字段在 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
目前 simple_form 不支持 rails 6 action_text 上的 ruby 和 rich_text_area 输入字段。 所以目前我的输入字段在 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