Ok, I know this is an old question, but just wanted to note, for others that may stumble across this:
The code snippet in the question is from FriendlyId 3.x in which case you would add a column to your table (call it anything except for slug
... I prefer to use cached_slug
) as a string and update the model to show
Class Product < ActiveRecord::Base
has_friendly_id :name, :use_slug => true, :cache_column => 'cached_slug'
end
As of friendly_id 4.x, you simply just add a slug
column as a string
to the table, and use the new syntax:
eg:
Class Product < ActiveRecord::Base
extend FriendlyId
friendly_id :name, :use => :slugged
end
There are a whole bunch of options and ways to get the most out of friendly_id including historical records (to avoid 404s) etc ...
More information: http://rubydoc.info/github/norman/friendly_id/master/frames