轨道 6 动作文本.表单可以使用多个富文本字段吗?



我在 rails 6 应用程序的表单中使用了多个富文本字段,但只有第一个字段存储在数据库中,其余字段根本不显示在数据库中。

module.rbhas_rich_text :content
has_rich_text :referenceshas_rich_text :footnotes


_form.html.erbf.rich_text_area :content f.rich_text_area :references
f.rich_text_area :footnotescontroller.rb


params.require... :content
, :references, :footnotes

...

您需要覆盖输入的id属性,如下所示:

<%= form.rich_text_area :footnotes, class: "", id: "modelname_#{form_model.id}_footnotes" %>,其中 id 是必须唯一的任意字符串,如 "chapter_1_footnotes"。

是的,这可以工作,但请确保您的has_rich_text :attribute_name 的名称与模型上的任何属性名称都不匹配。

最新更新