· 1 min read

Screencast: Pretty URLs mit FriendlyId

Downloads in verschiedenen Formaten:

mp4 m4v webm ogg

Resourcen:

terminal

[bash] rails g migration add_slug_to_articles slug:string rake db:migrate rails c rails g friendly_id [/bash]

rails console

[ruby] Article.find_each(&:save) [/ruby]

db/migrate/add_slug_to_articles.rb

[ruby] add_column :articles, :slug, :string add_index :articles, :slug [/ruby]

models/article.rb

[ruby] class Article < ActiveRecord::Base extend FriendlyId friendly_id :name, use: :slugged

def should_generate_new_friendly_id? new_record? end end

# Or…

class Article < ActiveRecord::Base extend FriendlyId friendly_id :name, use: :history end [/ruby]

Back to Blog