views:

13

answers:

1

I have some orders with nested items and the items have nested kinds. When i do a form_for @order in a view, then i would like to hide all the items that have their :registered attribute set to true

<% form_for @order do |f| %>
  <% f.fields_for :items do |ff| %>
    <%# show all the items that have :registered == false %>
  <% end %>
<% end %>

or

def register
  @order = Order.find(params[:id])
  # Sort out the :registered == true
end
+2  A: 

You can try something like this:

<% 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 %>

Or you can create a second association for unregistered items:

class Order < ActiveRecord::Base
  has_many :unregistered_itmes, :class_name => "Item", :conditions => { :registered => false } 
end

And then you can do something like this:

<% form_for @order do |f| %>
  <% f.fields_for :unregistered_items do |ff| %>
    <%# show all the items that have :registered == false %>
  <% end %>
<% end %>
jigfox
that gives a SyntaxError
Flexo
sorry, my bad.. it worked
Flexo