Here is what I would do. I''m new to this, so perhaps there is a
better way.
I would take out the Order.find statement.
Instead, take advantage of the methods Rails gives you for free when
you set up the belongs_to and has_many relationship.
For example, you could use the following inside your main loop:
for order in client.orders
instead of
for order in @all_orders
On Jul 27, 11:11 am, MagicLava
<magicl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I have 2 tables (clients and orders). I have create models for them
> both and the relevant belongs_to has_many declarations.
>
> I''ve created a controller which has the following code:
>
> def list_orders
> @all_clients = Client.find(:all)
> @all_orders = Order.find(:all)
> end
>
> I''ve created a view which has the following code:
> <% for client in @all_clients %>
> <%=h(client.name) %>
> <% for order in @all_orders %>
> <%=h(order.detail) %>
> <% end %>
> <% end %>
>
> Now what i want to see is a list of clients with their individual
> order details listed underneath. Instead of course im seeing each
> client with *every* client order detail listed underneath. The
> problem I have is that I dont know how to pass the *current* client id
> to the *order* loop to get a true parent/child view.
>
> I''m missing something really basic here, but its stumping me at
the
> moment.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---