Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prepopulating admin user in database with authlogic rails plugin

I've been using the Authlogic rails plugin. Really all I am using it for is to have one admin user who can edit the site. It's not a site where people sign up accounts. I'm going to end up making the create user method restricted by an already logged in user, but of course, when I clear the DB I can't create a user, so I have to prepopulate it somehow. I tried just making a migration to put a dump of a user I created but that doesn't work and seems pretty hacky. What's the best way to handle this? It's tricky since the passwords get hashed, so I feel like I have to create one and then pull out the hashed entries...

like image 753
V_H Avatar asked Dec 14 '22 02:12

V_H


1 Answers

Rails 2.3.4 adds a new feature to seed databases.

You can add in your seed in db/seed.rb file:

User.create(:username => "admin", :password => "notthis", :password_confirmation => "notthis", :email => "[email protected]")

Then insert it with:

rake db:seed

for production or test

RAILS_ENV="production" rake db:seed  
RAILS_ENV="test" rake db:seed

My favorite feature in 2.3.4 so far

like image 65
nkassis Avatar answered Apr 26 '23 21:04

nkassis