Skip to content

Instantly share code, notes, and snippets.

@hernamesbarbara
Created February 19, 2012 17:10
Show Gist options
  • Save hernamesbarbara/1864672 to your computer and use it in GitHub Desktop.
Save hernamesbarbara/1864672 to your computer and use it in GitHub Desktop.
Create Admin User in Ruby on Rails Application using rake db:seed
#db/seeds.rb
# Run 'rake db:seed' from terminal to create an Admin User in your database
#Seed DB with at least 1 Admin User
admin=User.new({ name: "Admin User", email: 'admin@rubyonrails.com',
password: 'password', password_confirmation: 'password'})
admin.toggle!(:admin)
if admin.valid?
admin.save()
elsif admin.errors.any?
admin.errors.full_messages.each do |msg|
puts msg
end
else
puts "****NOT VALID****"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment