目前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
并有一个富文本区域?
在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能把它添加到主文件中。