You are here: Browse Railsplugins Acts As Seo Friendly
A Ruby on Rails plugin that swaps the commonly used numeric :id based URLs (/posts/34), for more useful & human readable URLs like (/posts/34-my-latest-spoon-collection)
http://www.chrisfarms.com
declare a field in your model that you wish to use for the textual
slug with the acts_as_friendly_param macro.
class Post < ActiveRecord::Base
acts_as_friendly_param :name
end
That's it!
The result of the Post#name method will be appended to the URL
helpers like:
<%= link_to 'view post', :action => 'show', :id => @post %>
will produce URLs like
/posts/12-monkies-are-coming
Although many unicode characters are actually valid in URIs, the
rails url helpers are quite strict with their escaping and you can
end up with some pretty ugly urls.
It is also good for searching if e and é are treated equally.
So.. friendly-param will try to tidy up the following:
To prevent multiple URLs pointing to the same resource, and having
a negative effect on search-engine ranking, friendly-url will
use 301 redirects on any ambiguous GET requests.
The following behavior should be expected
Once a model has is acting as a friendly param then #find will not
act the same for String/Fixnum objects.
Post.find('8') =>> RecordMoved Error
Post.find(8) =>> OK
Ensure that you use don't call #id directly when using url_for
eg.
<%= link_to 'show animal', :action => 'show', :id => @animal %>
NOT
<%= link_to 'show animal', :action => 'show', :id => @animal.id %>
NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly