Skip to content

Instantly share code, notes, and snippets.

@D3xx73r
Last active August 29, 2015 13:58
Show Gist options
  • Save D3xx73r/10303220 to your computer and use it in GitHub Desktop.
Save D3xx73r/10303220 to your computer and use it in GitHub Desktop.
Rake task to bootstrap admins in a Rails app
# 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