launchscout / nku

NKU Class Spring
5 stars 14 forks source link

How can an administrator sign up? #81

Closed ShikhaBhattarai closed 10 years ago

mitchlloyd commented 10 years ago

Usually in applications we don't let people sign up as administrators. Administrators can sometimes create other administrators or promote other users to become an administrator. For this assignment we aren't requiring any interface to create administrators or promote users to become an administrator.

In any case, how do we typically get the first administrator? One option is to use the Rails seeds.rb file to create an administrator in code:

# In seeds.rb
if Administrator.count.zero?
  Administrator.create!(password: "default_password", password_confirmation: "default_password")
end

# Or if you are using a user promoted to admin
if User.where(admin: true).count.zero?
  User.create!(password: "default_password", password_confirmation: "default_password", admin: true)
end

This file runs whenever someone creates a new instance of your application or migrates the database. You can also run it on it's own my running rake db:seed. It's important that this seeds.rb script is idempotent, meaning that running it multiple times won't keep adding more and more users.

For this assignment, Kevin and I will work from the Rails console to create administrator users or update users to administrators to use in testing.