I have a model that has the following classes: ShoppingList, Item and
-- *Product* is just a list of product names: Apple, Orange, Banana,
Grape. The table has two columns: ID and NAME.
-- A *ShoppingList* has a name (string) and many *Item* objects.
-- Each *Item* has a *quantity* (integer) and to-one relationship to
My ShoppingList's edit view has a form that contains a textfield for
the name of
a shopping list and a table of items and their quantities:
The Qty. is an editable text field. The Item is a non-editable text
The model object for this view is, of course, a ShoppingList.
I am trying to bind each text field to the quantity attribute of each
item in the shopping list. I tried something like this but it doesn't
work because Rails wants an instance variable to bind to. How do I
properly bind my array?
<% @shopping_list.items.each do |item| %>
<td><%= text_field("shopping_list.items[" + item.id.to_s +
item.quantity, :size => 3) %></td><td><%= (Product.find
<% end %>