easy friendly urls with rails just use friendly_id
Cedric 11/02/2012 10:03 friendly_id 0 comments
Cedric 11/02/2012 10:03 friendly_id 0 comments
I wanted to have some nice URL for my blog, after googling the possible alternatives I found Friendly_Id
This solution is really easy to implement. I had just to change few things from the documented setup.
to add the slug to my Post model, I create the migration this way:
rails generate migration add_slug_to_posts slug:string
and for the index addition:
add_index :users, :slug, :unique => :true
For the Post model I add in app/models/post.rb these lines:
extend FriendlyId
friendly_id :title, :use => :slugged
After restarting my application and the apache server it is just working perfectly!