I have a shopping cart screen where I display my available item and all it''s description info and then want to have the user enter a quantity. I show all my item fields, e.g. <%= @item.item_id %> Then I have a field defined <%= text_field ''shopping_cart_item'' , ''quantity'' %> In my controller, how do I access this data? I''ve tried many different ways, I just want to get this quantity first to validate that it''s a number, that it''s less than the quantity available, etc, then create a shopping cart record. Help, I''ve spent a long time on this. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
So i changed my view to include <% text_field_tag ''quantity'' %> and I changed my controller''s first line to say quantityordered = params[:quantity] Is this correct? -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Nov 28, 2008, at 1:32 PM, Joe Smith wrote:> > I have a shopping cart screen where I display my available item and > all > it''s description info and then want to have the user enter a quantity. > I show all my item fields, e.g. > > <%= @item.item_id %> > > Then I have a field defined > > > > <%= text_field ''shopping_cart_item'' , ''quantity'' %> > > In my controller, how do I access this data? > > I''ve tried many different ways, I just want to get this quantity first > to validate that it''s a number, that it''s less than the quantity > available, etc, then create a shopping cart record. > > Help, I''ve spent a long time on this. > --You probably knew this, but you need a form. So maybe: <% form_for(@cart) do |f| -%> <%= f.text_field :quantity %> <%= submit_tag(''ok'') %> <% end -%> That should get you a form. So, fire the thing up, watch your logs, enter something into the quantity text box and what happens? You get a params hash passed back to the controller. In that hash is: :cart => { :quantity => "3" } So in your controller, probably in the create method, just do something like: quantity = params[:cart][''quantity''] But if all you are doing is validating, you should try to do this in the model anyhow. Hope this helps. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
It seems to ''work'' (doesn''t abort), but when I store it in my database I have a null value -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Look at the Dev logs, see the params hash and use that in controller. Http://www.rubyplus.org Free Ruby & Rails screencasts On Nov 28, 2008, at 3:52 PM, Joe Smith <rails-mailing-list@andreas- s.net> wrote:> > So i changed my view to include > > <% text_field_tag ''quantity'' %> > > and I changed my controller''s first line to say > > quantityordered = params[:quantity] > > Is this correct? > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---