I have looked at examples for this. I found a similar example in the Agile Web Dev... book but that didn''t help. Here''s what i am trying to do. A Cart has many line items. On the Display Cart page, I want to provide the user the option to update quantities. Here''s the rhtml code: <%= start_form_tag :action => ''update_cart'' %> <% for @item in @items %> <%= @item.product.title %> <%= text_field "item[]",''quantity'' %> <%= number_to_currency(@item.unit_price) %> $<%= @item.quantity * @item.unit_price %> <%= link_to ''Remove item'', {:action => ''remove_from_cart'', :id => @item.product} %> <% end %> Total $ <%= @cart.total_price %> <%= submit_tag ''Update Cart'' %> <%= end_form_tag %> In the Page->View source I find that all text boxes have the name item[quantity]. I expected the names to be item[0][quantity], item[1][quantity] and so on. And instead of passing all the rows as params, only the first row (i.e. first line item) is being passed to the update_cart function. I''ve spent 3 days on this. Please help !! -- Posted via http://www.ruby-forum.com/.
Though i am having similar kind of problem....but there is a option called index or something...using which you can index your keys. But for me...real problem lies...within the fact that....ideally <%= file_field :picture "image" %>, here image should be a method within the model class...now....if i have a array of images...then how can i assign same key to all of them? On 4/24/06, Nikhilesh <nikhilesh@gmail.com> wrote:> > I have looked at examples for this. I found a similar example in the > Agile Web Dev... book but that didn''t help. Here''s what i am trying to > do. > > A Cart has many line items. On the Display Cart page, I want to provide > the user the option to update quantities. > > Here''s the rhtml code: > <%= start_form_tag :action => ''update_cart'' %> > <% for @item in @items %> > <%= @item.product.title %> > <%= text_field "item[]",''quantity'' %> > <%= number_to_currency(@item.unit_price) %> > $<%= @item.quantity * @item.unit_price %> > <%= link_to ''Remove item'', {:action => ''remove_from_cart'', :id > => > @item.product} %> > <% end %> > Total > $ <%= @cart.total_price %> > <%= submit_tag ''Update Cart'' %> > <%= end_form_tag %> > > In the Page->View source I find that all text boxes have the name > item[quantity]. I expected the names to be item[0][quantity], > item[1][quantity] and so on. > And instead of passing all the rows as params, only the first row (i.e. > first line item) is being passed to the update_cart function. > > I''ve spent 3 days on this. Please help !! > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- nothing much to talk -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060424/349aee07/attachment.html
yeah its really simple: <%= text_field "item", "quantity", :index => @item.unit_price %> On 4/24/06, hemant <gethemant@gmail.com> wrote:> > Though i am having similar kind of problem....but there is a option called > index or something...using which you can index your keys. But for me...real > problem lies...within the fact that....ideally <%= file_field :picture > "image" %>, here image should be a method within the model class...now....if > i have a array of images...then how can i assign same key to all of them? > > > > > On 4/24/06, Nikhilesh <nikhilesh@gmail.com> wrote: > > > > I have looked at examples for this. I found a similar example in the > > Agile Web Dev... book but that didn''t help. Here''s what i am trying to > > do. > > > > A Cart has many line items. On the Display Cart page, I want to provide > > the user the option to update quantities. > > > > Here''s the rhtml code: > > <%= start_form_tag :action => ''update_cart'' %> > > <% for @item in @items %> > > <%= @item.product.title %> > > <%= text_field "item[]",''quantity'' %> > > <%= number_to_currency(@item.unit_price) %> > > $<%= @item.quantity * @item.unit_price %> > > <%= link_to ''Remove item'', {:action => ''remove_from_cart'', > > :id => > > @item.product} %> > > <% end %> > > Total > > $ <%= @cart.total_price %> > > <%= submit_tag ''Update Cart'' %> > > <%= end_form_tag %> > > > > In the Page->View source I find that all text boxes have the name > > item[quantity]. I expected the names to be item[0][quantity], > > item[1][quantity] and so on. > > And instead of passing all the rows as params, only the first row (i.e. > > first line item) is being passed to the update_cart function. > > > > I''ve spent 3 days on this. Please help !! > > > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > -- > nothing much to talk >-- nothing much to talk -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060424/f66b5dc4/attachment-0001.html
hemant kumar wrote:> yeah its really simple: > > <%= text_field "item", "quantity", :index => @item.unit_price %>Thanks. If i do this then the parameters passed will be item[0]=>quantity=><i>n1</i> item[1]=>quantity=><i>n2</i> item[2]=>quantity=><i>n3</i> and so on... How do i read this at the server? Now this becomes a Ruby language question actually and not a Rails question. This is just an enhancement to the Depot application in the Agile Web Dev book. The objective is to update all the quantities of all the line items of the cart. -- Posted via http://www.ruby-forum.com/.