0

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

1 Answer 1

2

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 %>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.