Reputation: 169
Here's the problem, when visiting requests/index.html.erb:
Routing Error
No route matches {:action=>"cancel", :controller=>"requests"}
index.html.erb:
<%= link_to "Cancel", cancel_request_path %>
routes.rb:
resources :requests do
get 'cancel', on: :member
end
requests_controller.rb:
def cancel
request = Request.find(params[:id])
request.update_attributes(stage: "Cancelled")
redirect_to root_path
end
What am I missing?
Upvotes: 0
Views: 120
Reputation: 169
Fixed. I just needed to change to this in my index.html.erb:
<%= link_to "Cancel", cancel_request_path(request.id) %>
I thought all the attributes of the object would get passed to the action in params, but I guess I have to specify which params to pass to the action.
Upvotes: 1
Reputation: 9362
get 'cancel', :on => :member
On member means, you path would be like :
cancel_requests_path(:id=>request_id)
or simply the requests object in the parameter...
Upvotes: 0