Skip to content

Instantly share code, notes, and snippets.

@spk
Created September 6, 2011 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spk/1197471 to your computer and use it in GitHub Desktop.
Save spk/1197471 to your computer and use it in GitHub Desktop.
Regenerate all the friendly_id slugs for models using friendly_id
# encoding: utf-8
namespace :slugs do
desc "Regenerate all the friendly_id slugs for models using friendly_id"
task :regenerate => [:environment] do
models = ActiveRecord::Base.connection.tables.map(&:classify) - ["SchemaMigration", "Version"]
models.select {|m| m.constantize.uses_friendly_id? }.each do |model|
puts "* (Re)generating slugs for model #{model}" if verbose
sh "rake friendly_id:redo_slugs MODEL=#{model}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment