class Client
has_many :orders
end
def list_orders
@all_clients = Client.find(:all, :include=>[:orders])
end
for client in all_clients
<%=client.name%>
for order in client.orders
<%=order.id%>
end
end
On Fri, 2007-07-27 at 09:11 -0700, MagicLava 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
-~----------~----~----~----~------~----~------~--~---