Skip to content

Instantly share code, notes, and snippets.

@speed-of-light
Forked from wrburgess/namespace.rake
Created January 26, 2014 17:52
Show Gist options
  • Select an option

  • Save speed-of-light/8636651 to your computer and use it in GitHub Desktop.

Select an option

Save speed-of-light/8636651 to your computer and use it in GitHub Desktop.
rails seeds templates
namespace :project_name do
require 'csv'
desc 'Migrate previous user database'
task :migrate_users => [:environment] do
input = ''
STDOUT.puts 'Seed with previous users?'
input = STDIN.gets.chomp
if input == 'y'
puts 'Executing tasks...'
CSV.foreach("#{Rails.root}/db/fill/previous_users.csv", :headers => :first_row) do |row|
User.create!({
password: (0...8).map{(65+rand(26)).chr}.join,
email: row[0],
salutation: row[1],
first_name: row[2],
last_name: row[3]
}, without_protection: true
)
puts 'User created'
end
else
puts 'Aborting tasks...'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment