Skip to content

Instantly share code, notes, and snippets.

@jacortinas
Created April 6, 2011 22:30
Show Gist options
  • Save jacortinas/906685 to your computer and use it in GitHub Desktop.
Save jacortinas/906685 to your computer and use it in GitHub Desktop.
Creates an admin user from the command line, hides the input of the password fields. Also show colorized errors and success output.
require 'highline'
hl = HighLine.new
desc "Create an admin user for the current environment"
task :create_admin => :environment do
puts "\n== Creating an admin ==\n"
email = hl.ask(' Email: ')
password = hl.ask(' Password: ') { |q| q.echo = '*' }
confirm = hl.ask(' Password confirmation: ') { |q| q.echo = '*' }
user = User.new(:email => email, :password => password, :password_confirmation => confirm)
if user.save
puts hl.color("\n== Admin created successfully! ==\n", :green)
else
puts hl.color("\n== There were errors creating the admin! ==", :red)
user.errors.full_messages.each do |message|
puts " #{message}"
end
puts
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment