我有一些嵌套项目的订单,这些项目有嵌套种类。当我在视图中执行form_for @order
时,我想隐藏其:registered
属性设置为 true
<% form_for @order do |f| %>
<% f.fields_for :items do |ff| %>
<%# show all the items that have :registered == false %>
<% end %>
<% end %>
或
def register
@order = Order.find(params[:id])
# Sort out the :registered == true
end
答案 0 :(得分:2)
您可以尝试这样的事情:
<% form_for @order do |f| %>
<% f.fields_for :items do |ff| %>
<% next if ff.object.registered %>
<%# show all the items that have :registered == false %>
<% end %>
<% end %>
或者您可以为未注册的项目创建第二个关联:
class Order < ActiveRecord::Base
has_many :unregistered_itmes, :class_name => "Item", :conditions => { :registered => false }
end
然后你可以这样做:
<% form_for @order do |f| %>
<% f.fields_for :unregistered_items do |ff| %>
<%# show all the items that have :registered == false %>
<% end %>
<% end %>