Hi all, I''m following the shop example in ''Agile Web Development with Rails''. I would like to extend the checkout screen, in such a way people can change the number of items they have selected in there cart. In my controller I have: def checkout @cart = find_cart @items = @cart.items if @items.empty? redirect_to_index("There''s nothing in your cart!") else @order = Order.new @address = Address.new end end I also created the following checkout.rhtml file: <% @page_title = "Checkout" -%> <%= error_messages_for(:order) %> <%= start_form_tag(:action => "update_order") %> <table> <%= render(:partial => ''orderitem'', :collection => @items) %> </table> <%= submit_tag "Update" %> <%= end_form_tag %> Finally I created the following partial: <% product = orderitem.product %> <tr> <td><%= check_box ''orderitem'', ''delete'', ''index'' => orderitem_counter %></td> <td><%= text_field ''orderitem'', ''quantity'', ''value'' => orderitem.quantity, ''index'' => orderitem_counter, :size => 4 %></td> <td><%= product.brand %> <%= product.title %></td> </tr> Now when the user submits the form, I would like to read the quantity for each line_item and update my cart accordingly. Also, if the checkbox is checked I would like to delete the line_item from the cart. I have no clue how to do this in my controller.... Can you give me a hint? Regards, Harm de Laat _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Can somebody please comment on this? I''m realy stuck on this, and would like to move on.... Many thanks in advance! Regards, Harm de Laat On 12/25/05, Harm de Laat <harmdelaat-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi all, > > I''m following the shop example in ''Agile Web Development with Rails''. > > I would like to extend the checkout screen, in such a way people can > change the number of items they have selected in there cart. > > In my controller I have: > > def checkout > @cart = find_cart > @items = @cart.items > if @items.empty? > redirect_to_index("There''s nothing in your cart!") > else > @order = Order.new > @address = Address.new > end > end > > > I also created the following checkout.rhtml file: > > <% @page_title = "Checkout" -%> > > <%= error_messages_for(:order) %> > > > <%= start_form_tag(:action => "update_order") %> > > <table> > <%= render(:partial => ''orderitem'', :collection => @items) %> > </table> > > <%= submit_tag "Update" %> > > > <%= end_form_tag %> > > Finally I created the following partial: > > <% product = orderitem.product %> > > <tr> > <td><%= check_box ''orderitem'', ''delete'', ''index'' => orderitem_counter > %></td> > <td><%= text_field ''orderitem'', ''quantity'', ''value'' => > orderitem.quantity, ''index'' => orderitem_counter, :size => 4 %></td> > <td><%= product.brand %> <%= product.title %></td> > </tr> > > > Now when the user submits the form, I would like to read the quantity for > each line_item and update my cart accordingly. Also, if the checkbox is > checked I would like to delete the line_item from the cart. > > I have no clue how to do this in my controller.... > > Can you give me a hint? > > Regards, > > Harm de Laat > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 26 Dec 2005, at 10:47, Harm de Laat wrote:> Can somebody please comment on this? I''m realy stuck on this, and > would like to move on.... > > [...] > > when the user submits the form, I would like to read the quantity > for each line_item and update my cart accordingly. Also, if the > checkbox is checked I would like to delete the line_item from the > cart. > > I have no clue how to do this in my controller.... > > Can you give me a hint?Loop through the collection that''s submitted, check if the delete button is checked and delete the item if so. If not then update the item quantity. What part are you getting stuck on? Yours, Craig -- Craig Webster | t: +44 (0)131 516 8595 | e: craig-07VhxHapISisTnJN9+BGXg@public.gmane.org Xeriom.NET | f: +44 (0)709 287 1902 | w: http://xeriom.net