Tôi đã cố gắng lấy một số mã được tìm ra. Tôi có một hình thức tôi đang cố gắng sử dụng đá quý Wicked và Cocoon. Mọi thứ hoạt động, bao gồm cả chức năng link_to_add_association
. Tôi đang hiển thị một phần cho các trường biểu mẫu liên quan giống như Cocoon đề xuất và mọi thứ dường như chỉ hoạt động ngoại trừ chức năng link_to_remove_association
. Nó trả về lỗi sau:Rails Cocoon Gem: Chưa xác định Phương thức 'new_record?' trên link_to_remove_association với Wicked
không xác định phương pháp new_record?
cho nil: NilClass
Dưới đây là của tôi phần được ném lỗi:
<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>
Đây là quan điểm cho rằng đang kêu gọi các phần:
<%= simple_form_for @vendor, url: wizard_path do |f| %>
<div id="locations">
<%= f.simple_fields_for :locations do |location| %>
<%= render 'location_fields', :f => location %>
<% end %>
<div class="links">
<%= link_to_add_association 'add location', f, :locations %>
</div>
</div>
<div class="actions">
<%= f.submit "Continue" %>
</div>
<% end %>
Dưới đây là hành động điều khiển gọi chế độ xem:
class UserStepsController < ApplicationController
include Wicked::Wizard
steps :personal, :locations
def show
@vendor = current_vendor_user.vendor
@vendor.locations.build
render_wizard
end
Trong trường hợp nó giúp, đây là chức năng trong kén được ném lỗi:
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
Tôi chưa bao giờ đoán được điều đó. Cảm ơn! – Tim