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 car. It needs to be a POST, What's the way I should be doing this in rails?
<% @cars.each do |car| %> <tr> <td><%= button_to '+', {:controller => "votes", :action => "create"}, :car_id => car.id, :user_id=> session[:user_id] , :method=>:post %></td> <td><%= car.votes.count %></td> <td><%= car.name %></td> <td><%= car.code %></td> <td><%= car.album %></td> <% end %>
<td><%= button_to '+', {:controller => "votes", :action => "create", :car_id => car.id, :user_id=> session[:user_id]} , :method=>:post %></td>
This will make params[:car_id] and params[:user_id] available in VotesController create action.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With