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...
Accepting user_id as an untrusted input from the client is a
Very Bad Idea. If it's a value saved in session you can and
should fetch it in your controller.
def add_to_cart(user_id, product_id)
@cart = Cart.new(user_id, product_id )
end
"wrong number of arguments (given 0, expected 2)"
So where are you setting user_id and product_id from the params?
I assume you've looked at the log and confirmed the params hash
contains what you expect?
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:
Not clear what params[:id] would be set to in your example, but you went out of your way to whitelist cart[product_id], so that's what I think you should use.