问题描述
我一直在使用Authlogic Rails插件。真的所有我使用它是有谁可以编辑站点一个管理员用户。这不是一个网站,人们注册帐户。我将最终使受限制的用户创建的方法已经登录的用户,当然,当我清楚我不能创建一个用户数据库,所以我必须prepopulate它在某种程度上。我试着只是让迁移把我创建了一个用户转储但是,这并不工作,似乎pretty哈克。什么是处理这个问题的最好方法?这是棘手,因为密码散列得到,所以我觉得我有创建一个,然后拉出散列条目...
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...
推荐答案
Rails的2.3.4增加了一个新功能,种子库。
Rails 2.3.4 adds a new feature to seed databases.
您可以用dB / seed.rb文件在你的种子补充:
You can add in your seed in db/seed.rb file:
User.create(:username => "admin", :password => "notthis", :password_confirmation => "notthis", :email => "[email protected]")
然后将其插入
rake db:seed
有关生产或测试
RAILS_ENV="production" rake db:seed
RAILS_ENV="test" rake db:seed
在2.3.4我最喜欢的功能至今
My favorite feature in 2.3.4 so far
这篇关于在authlogic数据库prepopulating管理员用户Rails插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!