Ysh*_*rov 1 activerecord ruby-on-rails 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'
Run Code Online (Sandbox Code Playgroud)
如何使其工作= 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
Run Code Online (Sandbox Code Playgroud)
在 application.scss 中:
//simple_form input for rich_text_area hight
trix-editor.form-control {
height: auto;
}
Run Code Online (Sandbox Code Playgroud)
现在在 posts/_form.html.haml 中,您可以执行以下操作:
= f.input :description, as: :rich_text_area
Run Code Online (Sandbox Code Playgroud)
一直希望在某个时候 simple_form 必须将它添加到 master
来源 1:https : //github.com/heartcombo/simple_form/issues/1638
来源 2:https : //github.com/heartcombo/simple_form/pull/1646
| 归档时间: |
|
| 查看次数: |
1109 次 |
| 最近记录: |