Last active
August 29, 2015 13:58
-
-
Save D3xx73r/10303220 to your computer and use it in GitHub Desktop.
Rake task to bootstrap admins in a Rails app
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
# With bash: | |
# $rake admin:bootstrap[email,first_name,last_name,password] | |
# With ZSH | |
# $rake 'admin:bootstrap[email,first_name,last_name,password]' | |
# or | |
# $rake admin:bootstrap\[email,first_name,last_name,password\] | |
namespace :admin do | |
desc "Add first admin user" | |
task :bootstrap, [:email, :first_name, :last_name, :password] => :environment do |t, args| | |
if Admin.count == 0 | |
admin = Admin.new do |admin| | |
admin.first_name = args[:first_name] | |
admin.last_name = args[:last_name] | |
admin.email = args[:email] | |
admin.password = args[:password] | |
end | |
admin.save! | |
else | |
raise "Admin already bootstraped." | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment