On Sep 14, 4:12 pm, "David A. Black" <[email protected]> wrote: > Hi -- > > On Mon, 14 Sep 2009, Pardee, Roy wrote: > > > I think you want to use the fields_for helper so rails will give you > > an array of form params to hold the various items. You should also > > probably include a hidden text field in there to hold the id of each > > item so you know which quantity should go w/which item. > > Actually you shouldn't need a hidden field. I'm adapting this example > from something slightly different (my Item objects have a description > field, rather than quantity), but here's what I've got: > > <% @items.each do |item| %> > <% fields_for "items[]", item do |ff| %> > <p>Description: <%= ff.text_field :description %></p> > <% end %> > <% end %> > > and here's what's submitted to the controller in params: > > {"items"=>{"345698069"=>{"description"=>"third item"}, > "345698067"=>{"description"=>"first item"}, > "345698068"=>{"description"=>"second item"}}, > "commit"=>"Buy", > etc. } > > So now I can iterate through that hash, getting the id number and a > hash of attributes each time. > > David > > -- > David A. Black, Director > Ruby Power and Light, LLC (http://www.rubypal.com) > Ruby/Rails training, consulting, mentoring, code review > Book: The Well-Grounded Rubyist (http://www.manning.com/black2)
I did exactly that, and it shows the array, but not the identifiers, anything else I'm missing? --~--~---------~--~----~------------~-------~--~----~ 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

