[ACCEPTED]-pass parameter by link_to ruby on rails-parameters
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 5 find in your 'cars' table (as with rails 4 pluralization) in your DB a car with id 3 == to car.id
hope it helps! happy coding
more 2 than a year later, but if you see it or 1 anyone does, i could use the points ;D
The above did not work for me but this did
<%= link_to "text_to_show_in_url", action_controller_path(:gender => "male", :param2=> "something_else") %>
0
Maybe try this:
<%= link_to "Add to cart",
:controller => "car",
:action => "add_to_cart",
:car => car.attributes %>
But I'd really like to see 2 where the car object is getting setup for 1 this page (i.e., the rest of the view).
You probably don't want to pass the car
object 3 as a parameter, try just passing car.id
. What 2 do you get when you inspect(params)
after clicking "Add 1 to cart"?
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.