Subscribe to my Feed, follow me on Twitter, recommend me on Working With Rails or see my code on GitHub
ActsAsSluggable
This plugin is kind of deprecated, as it is now, after some recent changes in Rails, really easy to achieve this effect without the use of a plugin. Here’s how:
Define to_param in your model to return the slug.
class Article < ActiveRecord::Base
def to_param
id.to_s+'-'+title.downcase.gsub(' ', '-')
end
end
That’s it. Now you have the same effect right there in the model. You know exactly what it’s doing and where it is, and you can customise the process for each model. If you’re one of those DRY fanatics, put to_param in a module in /lib and include it in the models where you want slugs.
