
which is easy and totally amazing gem.
First thing First, Set Friendly_id gem in Gemfile
gem 'friendly_id'
Now,rails g migration add_slug_to_articles slug:string rake db:migrate rails c
>> Article.find_each(&:save) rails g friendly_id
db/migrate/add_slug_to_articles.rb
add_column :articles, :slug, :string add_index :articles, :slug
models/article.rb
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
Tags: Ruby on Rails Tutorials, Ruby on Rails Videos, Ruby Gems, Gems Use trick, Ruby code, Rails servers
Comments
Post a Comment