In the book ''Agile web development with Rails", the authors are building a store-like app. At some point they add dynamic adding a product with ajax call. [code] <!-- store_controller#index --> <% form_remote_tag :url => { :action => ''add_to_cart'', :id => product } do %> <%= submit_tag "Add to Cart" %> <% end %> [/code] [code] # store_controller.rb def add_to_cart product = Product.find(params[:id]) @cart = find_cart @current_item = @cart.add_product(product) # render xhr request [/code] [code] # model cart.rb / no DB table def add_to_cart(product) current_item = @items.find {|item| item.product == product} if current_item current_item.increment_quantity else current_item = CartItem.new(product) @items << current_item end current_item end [/code] Is there a way to add a text field which will represent the quantity of the product to add in the cart ? Customer enter quantity in text field, click Add to cart and the product and quantity is added to the model/cart. Thanks in advance -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
radhames brito
2010-Sep-19 12:21 UTC
Re: Depot app from ''Agile Web Development with Rails''
surely , but i warn you that that tutorial is very old, there are better way to do everything now. [code] <!-- store_controller#index --> <% form_remote_tag :url => { :action => ''add_to_cart'', :id => product } do %> <%= text_field_tag :quantity%> <%= submit_tag "Add to Cart" %> <% end %> [/code] [code] # store_controller.rb def add_to_cart product = Product.find(params[:id]) @cart = find_cart @current_item = @cart.add_product(product) # render xhr request [/code] [code] # model cart.rb / no DB table def add_to_cart(product) current_item = @items.find {|item| item.product == product} if current_item params[:quantity].blank? ? current_item.increment_quantity : current_item.quantity = params[:quantity] else current_item = CartItem.new(product) unless params[:quantity].blank? current_item.quantity params[:quantity] @items << current_item end current_item end [/code] -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
radhames brito
2010-Sep-19 12:24 UTC
Re: Depot app from ''Agile Web Development with Rails''
forgot to add the ''end'' current_item = CartItem.new(product)> unless params[:quantity].blank? >current_item.quantity = params[:quantity]> end > >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sun, Sep 19, 2010 at 8:21 AM, radhames brito <rbritom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> surely , but i warn you that that tutorial {in the book ''Agile web > development with Rails"} is very old, there are better way to do everything > now. > > >Are you saying they aren''t using the ''better ways" of doing things in the latest tutorial that is in their latest book for Rails 3? (Just curious because I''m using it as a guide for my learning as well.) -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
radhames brito
2010-Sep-19 21:03 UTC
Re: Depot app from ''Agile Web Development with Rails''
"Are you saying they aren''t using the ''better ways" of doing things in the latest tutorial that is in their latest book for Rails 3? (Just curious because I''m using it as a guide for my learning as well.) " the book for rails 3 is not out , it will be out in January 2011 http://pragprog.com/titles/rails4/agile-web-development-with-rails On Sun, Sep 19, 2010 at 2:40 PM, Rick R <rickcr-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sun, Sep 19, 2010 at 8:21 AM, radhames brito <rbritom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> surely , but i warn you that that tutorial {in the book ''Agile web >> development with Rails"} is very old, there are better way to do everything >> now. >> >> >> > > Are you saying they aren''t using the ''better ways" of doing things in the > latest tutorial that is in their latest book for Rails 3? (Just curious > because I''m using it as a guide for my learning as well.) > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 19 September 2010 22:03, radhames brito <rbritom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > "Are you saying they aren''t using the ''better ways" of doing things in the > latest tutorial that is in their latest book for Rails 3? (Just curious > because I''m using it as a guide for my learning as well.) " > > > the book for rails 3 is not out , it will be out in January 2011 > > http://pragprog.com/titles/rails4/agile-web-development-with-railsThe Beta version of the book is available now (as advertised on the link you gave). Colin> > > On Sun, Sep 19, 2010 at 2:40 PM, Rick R <rickcr-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> On Sun, Sep 19, 2010 at 8:21 AM, radhames brito <rbritom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>> surely , but i warn you that that tutorial {in the book ''Agile web >>> development with Rails"} is very old, there are better way to do everything >>> now. >>> >> >> Are you saying they aren''t using the ''better ways" of doing things in the >> latest tutorial that is in their latest book for Rails 3? (Just curious >> because I''m using it as a guide for my learning as well.) >> >> -- >> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
radhames brito
2010-Sep-19 21:15 UTC
Re: Depot app from ''Agile Web Development with Rails''
Yes but only if you buy it from pragmatic bookshelf ( i didnt : / ) its UD$53, but at amazon they have it for US$29. anyway i assumed he has the 3 edition. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.