Skip to content

Instantly share code, notes, and snippets.

@onpaws
Created February 13, 2014 01:39
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 onpaws/8968153 to your computer and use it in GitHub Desktop.
Save onpaws/8968153 to your computer and use it in GitHub Desktop.
Rake task to dump current Rails database into seeds.rb format
namespace :export do
desc "Prints Country.all in a seeds.rb way."
task :seeds_format => :environment do
Country.order(:id).all.each do |country|
puts "Country.create(#{country.serializable_hash.delete_if {|key, value| ['created_at','updated_at','id'].include?(key)}.to_s.gsub(/[{}]/,'')})"
end
end
end
#via http://xyzpub.com/en/ruby-on-rails/3.2/seed_rb.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment