Forum: Ruby on Rails (Nested) collection in a view

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Lucifron (Guest)
on 2006-03-13 16:45
(Received via mailing list)
Say I have a model consisting of Order( has_many :order_lines) and
belongs_to :order).

What would be the 'rails way' to create an order form?

Know I could just say @order = Order.some_order, @lines =
@order.order_lines, and use something like this..:

Order no: <%= %>
Date <%= date_select "order", "date" %>
<hr />
<% for line in @lines %>  # or use a partial..
  Amount: <%= text_field "lines[]", "amount" %>
<% end %>

..then add the lines to my Order in the controller.

I feel though, that I should be creating my whole order with[:order]). Is that feasible/possible/the right way?

If possible, please show me how i would call text_field with
@order.order_lines.amount -- or what the id/name fields should be if I
to write the input tag by hand.

View this message in context:
Sent from the RubyOnRails Users forum at
This topic is locked and can not be replied to.