Search code examples
ruby-on-railsfriendly-urlslugfriendly-id

Rails 4 + Friendly_id: URL not showing slug


I am using Friendly_ID for slugs on my site and it is working...sort of. I can access the routes correctly, but when I follow a link to the page, it still shows the id. For example, I have a link that shows the following:

<%= link_to "X", location_path(@location, :id => "1")

which displayed the url as localhost:3000/locations/1 so I changed the link to:

<%= link_to "X", location_path(@location, :id => "X")

which displays properly (localhost:3000/locations/X) but when you look at the href of the link in after you navigate to its page, it is displayed as <a ... href="/locations/X.X">...</a>.

Why is the link displaying X.X and not simple X?


Solution

  • You don't need to pass id to the location_path. It will be picked up from @location. Drop id from location_path and it should fix the problem.