Reputation: 503
resources :cars do
collection do
get :f01a
end
end
class CarsController < ApplicationController
def f01a
@user = User.find(params[:id])
@count = Count.find_by_user_id(@user)
@count.increment!(:f02)
redirect_to @user
end
end
<%= button_to "add f01", f01a_cars_path %>
I can't get this to work. I need to execute this code from a button.
Upvotes: 0
Views: 120
Reputation: 96954
button_to
sends a POST request, but your routing is setup to only accept GET requests. You should change it to:
resources :cars do
collection do
post :f01a
end
end
Since you're using params[:id]
in your action, but not sending it in at all, you'll need to pass it in your button_to
:
<%= button_to "add f01", f01a_cars_path(:id => something)
(Replace something
with whatever ID you want to pass.)
Upvotes: 2