Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Paths not using slug #333

Closed
joonty opened this Issue · 1 comment

1 participant

@joonty

Hi,

This is almost certainly not a bug, more just a question of how to use the plugin in the right way.

I have a Recipe model, and have added the lines as per the README:

class Recipe < ActiveRecord::Base
  extend FriendlyId
  friendly_id :name, use: :slugged
  #...

And have added the migration. All the records were updated successfully, and have a slug. Not only that, but going to /recipes/<this-is-a-slug> works.

However, I assumed (quite possibly incorrectly) that the path helper would then use the model's slug attribute rather than ID, so that all links to the recipes would go to /recipes/<slug> rather than /recipes/<id>. This isn't the case - they still all link to the ID.

Not only that but I've searched in vain all over the Internets to try and find someone else with the same problem. I've tried all of the following paths in my view file:

<%= link_to 'view recipe', recipe  # -> links to /recipes/<id> %>
<%= link_to 'view recipe', recipe_path(recipe) # -> links to /recipes/id %> 
<%= link_to 'view recipe', recipe_path(recipe.slug) # -> gives a routing error, "No route matches {:action=>"show", :controller=>"recipes", :id=>nil}" %> 

Could you let me know what I'm doing wrong?

Thanks a lot!

@joonty

This is no longer an issue - despite restarting my Rails server many times with no effect, it's now working!

@joonty joonty closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.