【问题标题】:Rails 6 ActionText. Can a form use multiple rich text fields?Rails 6 动作文本。一个表单可以使用多个富文本字段吗?
【发布时间】:2020-02-04 09:30:10
【问题描述】:

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

module.rb
has_rich_text :content
has_rich_text :references
has_rich_text :footnotes

_form.html.erb f.rich_text_area:内容
f.rich_text_area :参考
f.rich_text_area :footnotes

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

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-5 ruby-on-rails-6 trix actiontext


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多