我有这段代码
<%= semantic_form_for @tournament do |f| %>
<%= f.semantic_fields_for :courts do |builder| %>
<%= render :partial => "court_fields", :locals => { :f => builder } %>
<span class="links">
<%= link_to_add_fields "Add More Court", f, :courts %>
</span>
<% end %>
这是部分
<div class="nested_fields">
<%= f.input :name %>
<%= f.input :address %>
<%= f.input :city %>
<%= f.input :state %>
<%= f.input :zip %>
<%= f.input :phone %>
<%= f.input :contact_name %>
<%= link_to_remove_fields "Remove Court", f %>
</div>
但我真正需要的是还有部分的跨度,所以它封装在nested_fields div中......我试过了
<%= semantic_form_for @tournament do |f| %>
<%= f.semantic_fields_for :courts do |builder| %>
<%= render :partial => "court_fields", :locals => { :f => builder, :original_f => f } %>
<% end %>
和部分
<div class="nested_fields">
<%= f.input :name %>
<%= f.input :address %>
<%= f.input :city %>
<%= f.input :state %>
<%= f.input :zip %>
<%= f.input :phone %>
<%= f.input :contact_name %>
<%= link_to_remove_fields "Remove Court", f %>
<span class="links">
<%= link_to_add_fields "Add More Court", original_f, :courts %>
</span>
</div>
但是我在下面得到了这个错误...我做错了什么,也许我对部分的理解是关闭的,任何帮助都会受到赞赏...
undefined local variable or method `original_f' for #<#<Class:0x000001035d5a80>:0x000001035cd920>
我的助手
def link_to_remove_fields(name, f)
f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)")
end
def link_to_add_fields(name, f, association)
new_object = f.object.class.reflect_on_association(association).klass.new
fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
render(association.to_s.singularize + "_fields", :f => builder)
end
link_to_function(name, ("add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\")"))
end
答案 0 :(得分:0)
render(association.to_s.singularize + "_fields", :f => builder)
部分渲染中没有original_f
吗?