Links
Friendly
Categories
Friendly
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 ActiveRecord models.
Using FriendlyId, it's easy to make your application use URL's like:
http://example.com/states/washington
instead of:
http://example.com/states/4323454
FriendlyId Features
FriendlyId offers many advanced features, including: slug history and versioning, scoped slugs, reserved words, custom slug generators, and excellent Unicode support. For complete information on using FriendlyId, please see the {http://norman.github.com/friendly_id/file.Guide.html FriendlyId Guide}.
FriendlyId is compatible with Rails 2.2.x - 3.0.
Rails Quickstart
gem install friendly_id
rails my_app
cd my_app
# add to Gemfile
gem "friendly_id", "~> 3.0"
rails generate friendly_id
rails generate scaffold user name:string cached_slug:string
rake db:migrate
# edit app/models/user.rb
class User < ActiveRecord::Base
has_friendly_id :name, :use_slug => true
end
User.create! :name => "Joe Schmoe"
./script/server
GET http://0.0.0.0:3000/users/joe-schmoe
Docs, Info and Support
Bugs:
Please report them on the Github issue tracker for this project.
If you have a bug to report, please include the following information:
- Stack trace and error message.
- Version information for FriendlyId, Rails and Ruby.
- Any snippets of relevant model, view or controller code that shows how your are using FriendlyId.
If you are able to, it helps even more if you can fork FriendlyId on Github, and add a test that reproduces the error you are experiencing.
Credits:
FriendlyId was created by Norman Clarke, Adrian Mugnolo, and Emilio Tagua.
Copyright (c) 2008-2010, released under the MIT license.
Vitals
| Home | http://norman.github.com/friendly_id |
|---|---|
| Repository | git://github.com/norman/friendly_id.git |
| License | Rails' (MIT) |
| Tags |
friendly_id permalink seo slug url
|
| Rating | (19 votes) |
| Owner | Norman Clarke |
| Created | 18 January 2008 |
Comments
-
On Scenario 1, just add
has_friendly_id :title
(where :title is the column you want to be friendly)
-
Thanks for the feedback, Marcus. I have corrected the documentation.
-
is there an easy way to make the slug write to the same table as my model and i'd just add a field to that model for it?
-
this plugin has been moved to github.
http://github.com/norman/friendly_id/tree/master
-
I followed your tutorial but I got this error: undefined method `blog_url' for #<BlogController:0x237d258>
Also in the view I have the link pointing to the id of the post: <%= link_to @post.title, :action => "show", :id => @post.id %> Could you please help me fixing this problem since I'm a newbie to Rails?
-
I'm probably doing something silly, but when I do
rake friendly_id:make_slugs MODEL=user
I get
rake aborted! wrong constant name user
Any ideas?
-
In case anyone else has the same problem, I figured it out. The model name has to be capitalized, as in "User"
Also if you have already defined a slug method in your model you have to remove it.
-
Hi, just wanted say thanks for creating this plugin... works great with my existing app and took me less than five minutes to implement. Used it on jettyrae.com. Thanks again!
-
Just a short comment to anyone deploying friendly_id and use the strip_diacritics option on Heroku.com (worked locally though). I did this and for some reason it didn't strip swedish characters "åäö" to "aao". I temporarily fixed it by adding a few gsub commands to the normalize method in slug.rb like:
s.gsub!(/å/, 'a') s.gsub!(/ä/, 'a') s.gsub(/ö/, 'o')

