0
votes

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:

enter image description here

What am i missing?

If i directly access the Vine via

http://localhost:3000/clips/1

I get to the show page..

2
Can you confirm that the clip is added?claptimes
Yeap, i see it in the Index and in the DB.Mini John

2 Answers

3
votes

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.

2
votes

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])