Created
October 29, 2013 18:14
-
-
Save barce/7219798 to your computer and use it in GitHub Desktop.
code for creating a seeds.rb file from user objects
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 seeds in a seeds.rb format" | |
task :seeds_format => :environment do | |
User.order(:id).all.each do |user| | |
# doesn't work on dreamhost | |
puts "User.create(#{user.serializable_hash.delete_if { |key, value| ['created_at','updated_at','id'].include?(key)}.to_s.gsub(/[{}]/,'')})" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment