Friendly_id gem in rails application

Asp.net Tools
FriendlyId is the gem which allows to create pretty URL’s and work with human-friendly strings as if they were numeric ids for Active Record models.
And FriendlyId is the permalink plugins for Ruby on Rails.

For example :


By using FriendlyId, it’s easy to make your application use URL’s like:

http://myapp.heroku.com/states/washington

instead of:

http://myapp.heroku.com/states/4323454

The main features of FriendlyId is slug history and versioning, scoped slugs, reserved words, and custom slug generators.

First you have install Friendly_id gem
gem install friendly_id

Then create a rails application
rails new my_app

cd my_app

Include the gem in your gem file before bundle install
gem "friendly_id", "~> 4.0.0.beta8"

rails generate scaffold user name:string slug:string

Before using rake db:migrate
# edit db/migrate/*_create_users.rb
add_index :users, :slug, :unique => true

and

# edit app/models/user.rb
class User < ActiveRecord::Base
extend FriendlyId
friendly_id :name, :use => :slugged
end

User.create! :name => "Username"

Then run rails server . 



Thanks 
Sriram

Facebook Rss Twitter

Get Weekly News letter of Updates!