Reputation: 7941
I follow the Railscast Episode Pretty URLs with FriendlyId.
I'm on Rails4 and using the 5.0 stable branch on Friendly Id's Github Repo.
I followed the Tutorial:
My Model Clip.rb:
extend FriendlyId
friendly_id :title, use: :slugged
My Migration:
rails g migration AddSlugToClips slug:string
Edited the Migration:
class AddSlugToClips < ActiveRecord::Migration
def change
add_column :clips, :slug, :string
add_index :clips, :slug
end
end
With an empty Database i try to add a Clip and when i try to open it:
What am i missing?
If i directly access the Vine via
http://localhost:3000/clips/1
I get to the show page..
Upvotes: 0
Views: 2179
Reputation: 7941
Ok i found it, it has to do with the Version of Friendly Id
you are using.
Finders are no longer overridden by default. If you want to do friendly finds, you must do Model.friendly.find
rather than Model.find.
Upvotes: 3
Reputation: 3477
It is because when you edit an clip and alter its title its slug will be updated. So try to run the code with following changes.
class Clip < ActiveRecord::Base
extend FriendlyId
friendly_id :title, use: :slugged
def should_generate_new_friendly_id?
new_record?
end
end
friendly_id :title, use: :slugged # you must do MyClass.friendly.find(params[:id])
#or
friendly_id :title, use: [:slugged, :finders] # you can now do MyClass.find(params[:id])
Upvotes: 2