Rails link_to or button_to post request with parameters

前端 未结 4 510
悲哀的现实
悲哀的现实 2020-12-24 06:52

I have a restful (scaffold generated) controller and model for Votes, I am simply trying to add a field into the view that when clicked, will create a new vote for a given c

4条回答
  •  攒了一身酷
    2020-12-24 07:41

    <%= button_to '+', {:controller => "votes", :action => "create", :car_id => car.id, :user_id=> session[:user_id]} , :method=>:post  %>
    

    This will make params[:car_id] and params[:user_id] available in VotesController create action.

提交回复
热议问题