【发布时间】:2021-02-09 09:06:17
【问题描述】:
作为标题,我在模型中有一个序列化的字符串列:
class Product < ApplicationRecord
serialize :ingredient_fields, Array
end
ingrdient_field 有许多字符串,但存储在产品模型中的一列中。它不是嵌套对象。
但我不确定如何使用 simple_form 处理这些动态文本输入,或者我是否可以使用 cocoon 或 nested_form_fields 来处理这些行为。我用这些 gem 尝试了许多不同的方法来生成 html,例如:
<form>
<input name="product[ingredient_fields][]"> <button>remove</button>
<input name="product[ingredient_fields][]"> <button>remove</button>
<button>add ingredient</button>
</form>
但都失败了。
还是只能自己写html和js?
【问题讨论】:
标签: ruby-on-rails simple-form cocoon-gem