Pass by link_to ruby โโon rails parameter
I have this line of code:
<%= link_to "Add to cart", :controller => "car", :action => "add_to_cart", :car => car %> when im in the add_to_cart method ... how can i call: car please?
@car = Car.new(params[:car]) This does not work, because he says that I am trying to strengthen it.
I do not understand what happened; because I used this to create new users and it worked fine.
By the way, the car is my car.
Try:
<%= link_to "Add to cart", {:controller => "car", :action => "add_to_cart", :car => car.id }%> and then in your controller
@car = Car.find(params[:car]) which will find โcarsโ in your table (for example, with rail pluralization) in your database a car with id == to car.id
hope this helps! happy coding
more than a year later, but if you see it or anyone else, I can use the dots; D

Above did not work for me, but this one did
<%= link_to "text_to_show_in_url", action_controller_path(:gender => "male", :param2=> "something_else") %>
Perhaps try the following:
<%= link_to "Add to cart", :controller => "car", :action => "add_to_cart", :car => car.attributes %> But I really would like to see where the car object gets the setting for this page (i.e. the rest of the view).
You probably don't want to pass the car object as a parameter, just try passing car.id What do you get when you inspect(params) after clicking "Add to Cart"?