Controller action methods do not take parameters. You get the parameters 
from the `params` hash. Also, as was mentioned, do not send user_id as a 
param. It is a security error, and you don't need to because you can access 
the session in the controller:

def add_to_cart
  product_id = params["product_id"]
  user_id = session["user_id"]
  @cart = Cart.new(user_id, product_id)
  ...
end

On Wednesday, February 15, 2017 at 5:11:02 PM UTC-7, Joe Guerra wrote:
>
> I am pretty close to figuring this out...
>
> I've got this in my product show page....I'm trying to pass user_id & 
> product_id to my products controller, add_to_cart method...
>
>
> <%= button_to  'Add to Cart', {:controller => "products", :action => 
> "add_to_cart", :user_id=> session[:user_id], :product_id => @id   } , 
> :method=>:post  %>
>
>
> on the controller...
>
>
> def add_to_cart(user_id, product_id)
>
>
>     @cart = Cart.new(user_id, product_id )
>
> #
>
>
> end
>
>
> I get the error, 
>
> "wrong number of arguments (given 0, expected 2)"
>
>
>
> Any suggestions?
>
> Thanks,
>
> Joe
>
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/68dd77c8-3ddd-4647-b49c-a954a821813c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to