Skip to content

Instantly share code, notes, and snippets.

@mrichman
Created May 11, 2009 19:35
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 mrichman/110130 to your computer and use it in GitHub Desktop.
Save mrichman/110130 to your computer and use it in GitHub Desktop.
# RAILS_ROOT/lib/tasks/seed.rake
begin
require 'highline/import'
rescue LoadError
puts 'HighLine required, please run rake setup first'
end
namespace :db do
desc "Setup Database"
task :seed => :environment do
pass = ask('Admin Password: ', String) { |q| q.echo = false }
email = ask('Admin Email: ', String)
u = User.new
u.login = 'admin'
u.password = pass
u.password_confirmation = pass
u.first_name = 'Administrative'
u.last_name = 'User'
u.email = email
begin
u.save!
u.has_role! :admin # THIS CAUSES A FAILURE!!
puts "User '#{u.login}' created successfully!"
rescue
puts "There were problems with creating a user:"
puts u.errors.full_messages # THIS PRINTS NOTHING!!!
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment