Reputation: 319
When I try to generate one route as shown on Rails documentation (http://guides.rubyonrails.org/routing.html), such as:
get '/patients/:id', to: 'patients#show'
the route I generate doesn't have any prefix, i.e. I cannot create a link to that page, for example:
link_to "patient profile", prefix_path(patient)
However when I use resource routing, which generates all the routes at once, the routes created all have a prefix.
resources :patients
Why can I not get a prefix with the first method?
Upvotes: 0
Views: 39
Reputation: 10497
Rails creates all url helpers automatically every time you use resources
, but for custom routes, you need to specify it yourself using as
, for example:
get '/patients/:id', to: 'patients#show', as: 'patient_show'
And to use it:
<%= link_to "patient profile", patient_show_path(patient) %>
Upvotes: 1