Matt Fieldhouse
Matt Fieldhouse

Reputation: 169

Routing Error - No route matches

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

Answers (2)

Matt Fieldhouse
Matt Fieldhouse

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

Rahul garg
Rahul garg

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

Related Questions