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