FriendlyId For Friendly URL

FriendlyId is the “Swiss Army bulldozer” of slugging and permalink plugins for Ruby on Rails. It allows you to create pretty URL’s and work with human-friendly strings as if they were numeric ids for Active Record models.

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

instead of:

Rails Quickstart

add this to your Gemfile

gem "friendly_id", "~> 4.0.0.beta14"

create new file migration

class CreateSubCategories < ActiveRecord::Migration
  def up
    add_column :users, :slug, :string
    add_index :users, :slug, :unique => true

and your model

class User < ActiveRecord::Base
  extend FriendlyId
  friendly_id :name, :use => :slugged

About me
Interested about Ruby on Rails

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: