Created
April 6, 2011 22:30
-
-
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.
This file contains hidden or 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
| 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