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.
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.
–
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.