I’ve set the friendly_id gem up, and generated slugs for my model.
The slugs are all shown in my DB column, and if I run Event.friendly.find('my-event-name') in the console, it works perfectly.
My URL’s are still showing as organisation/1/events/1 though, when I check the result of the following link_to:-
<%= link_to organisation_event_path(event.organisation.id, event.id), class: 'btn btn-primary' do %>
I’ve also added
extend FriendlyId
friendly_id :title, use: :slugged
to my model.
When I visit the URL manually, it works with the friendly id - so it seems to be just the link_to helper that isn't working.
Could possibly be related to some additional setup required for nested routes here - but I can’t seem to find anything when I search.
resources :organisations do
resources :events
end
The answer seems to be that I need to change the
.idin my link_to, to.friendly_idlike so:-Would expected it to work without this but perhaps not.