在我的Rails 5应用程序中,我按照Ryan Bates的#196获取3个父对象的嵌套表单。当使用他的应用程序助手(下面)时,它返回3个新的字段集。为什么/在哪里循环关联?我怎样才能让它只渲染一次表单?
谢谢!
def link_to_add_fields(name, f, association)
new_object = f.object.send(association).klass.new
id = new_object.object_id
fields = f.simple_fields_for(association, new_object, child_index: id) do |f|
render(association.to_s.singularize + "_fields", f: f)
end
link_to(name, '#', class: "add_fields", data: {id: id, fields: fields.gsub("\n", "")})
end
答案 0 :(得分:0)
由于将相关的咖啡脚本添加到所有咖啡文件,会发生此行为。然后,每个application.js
文件都会将其添加到js.coffee
。