Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the link_to path to a non-resourceful route?

I have a non-resourceful route that uses a SHA token in the route. Here it is in my routes.rb file:

match 'permissions/confirm/:token' => 'permissions#confirm'

I can access the generated route, but I don't know what to pass in for the link_to helper.

Here is what I'm using for the link_to, which is not working:

<%= link_to "Give permission", confirm_permission_path(:token => @permission.token) %>

Thoughts?

like image 937
Scott Avatar asked Feb 19 '12 04:02

Scott


2 Answers

Add :as key to your route like match 'permissions/confirm/:token' => 'permissions#confirm', :as => :confirm_permissions

Then <%= link_to "Give permission", confirm_permissions_path(:token => @permission.token) %>

like image 200
Sergey Kishenin Avatar answered Sep 24 '22 01:09

Sergey Kishenin


You can always use rake routes to figure out what the name of a path is. I double-check the output of that rake task all the time to make sure I'm using the correct restful or non-restful route.

like image 23
whazzmaster Avatar answered Sep 26 '22 01:09

whazzmaster