Created
February 13, 2014 01:39
-
-
Save onpaws/8968153 to your computer and use it in GitHub Desktop.
Rake task to dump current Rails database into seeds.rb format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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