What is the path of link_to to an unnamed route?

I have an unscientific route that uses the SHA token on the route. Here it is in the routes.rb file:

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

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

Here is what I use for link_to, which does not work:

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

Thoughts?

+6
source share
2 answers

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

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

+11
source

You can always use rake routes to find out what the path name is. I keep checking the output of this rake task all the time to make sure that I am using the correct calm or unresponsive route.

+3
source

Source: https://habr.com/ru/post/908811/


All Articles