Ruby on rails Rails Cocoon Gem:未定义的方法&x27;新纪录&x27;在链接上删除与邪恶的关联
我一直在试图弄明白一些代码。我有一个表格,我正在尝试使用和茧宝石。一切正常,包括Ruby on rails Rails Cocoon Gem:未定义的方法&x27;新纪录&x27;在链接上删除与邪恶的关联,ruby-on-rails,ruby,cocoon-gem,wicked-gem,Ruby On Rails,Ruby,Cocoon Gem,Wicked Gem,我一直在试图弄明白一些代码。我有一个表格,我正在尝试使用和茧宝石。一切正常,包括链接到添加关联功能。正如Cocoon推荐的那样,我正在为相关表单字段渲染一个部分,除了link\u to\u remove\u association函数之外,一切似乎都在运行。它返回以下错误: 未定义的方法新记录?用于nil:NilClass 下面是我抛出错误的部分: <div class="nested-fields"> <div> <%= f.input :addres
链接到添加关联功能。正如Cocoon推荐的那样,我正在为相关表单字段渲染一个部分,除了link\u to\u remove\u association
函数之外,一切似乎都在运行。它返回以下错误:
未定义的方法新记录?
用于nil:NilClass
下面是我抛出错误的部分:
<div class="nested-fields">
<div>
<%= f.input :address1 %>
</div>
<div>
<%= f.input :address2 %>
</div>
<div>
<%= f.input :city %>
</div>
<div>
<%= f.input :state %>
</div>
<div>
<%= f.input :postal %>
</div>
<div>
<%= link_to_remove_association "remove task", f %>
</div>
</div>
def link_to_remove_association(*args, &block)
if block_given?
f = args.first
html_options = args.second || {}
name = capture(&block)
link_to_remove_association(name, f, html_options)
else
name = args[0]
f = args[1]
html_options = args[2] || {}
**is_dynamic = f.object.new_record?**
html_options[:class] = [html_options[:class], "remove_fields #{is_dynamic ? 'dynamic' : 'existing'}"].compact.join(' ')
hidden_field_tag("#{f.object_name}[_destroy]") + link_to(name, '#', html_options)
end
end
事实证明,我忘记了供应商模型上的接受
方法的嵌套属性。我从来没有想到这一点。谢谢
class UserStepsController < ApplicationController
include Wicked::Wizard
steps :personal, :locations
def show
@vendor = current_vendor_user.vendor
@vendor.locations.build
render_wizard
end
def link_to_remove_association(*args, &block)
if block_given?
f = args.first
html_options = args.second || {}
name = capture(&block)
link_to_remove_association(name, f, html_options)
else
name = args[0]
f = args[1]
html_options = args[2] || {}
**is_dynamic = f.object.new_record?**
html_options[:class] = [html_options[:class], "remove_fields #{is_dynamic ? 'dynamic' : 'existing'}"].compact.join(' ')
hidden_field_tag("#{f.object_name}[_destroy]") + link_to(name, '#', html_options)
end
end