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...
相关问题
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- java client program to send digest authentication
- Eager-loading association count with Arel (Rails 3
- How to specify memcache server to Rack::Session::M
相关文章
- Ruby using wrong version of openssl
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- How to add a JSON column in MySQL with Rails 5 Mig
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
Rails 2.3.4 adds a new feature to seed databases.
You can add in your seed in db/seed.rb file:
Then insert it with:
for production or test
My favorite feature in 2.3.4 so far
Most used approach is to have a rake task that is run after deployment to host with empty database.
Add a rake task:
If you are using >= Rails 2.3.4 the new features include a db/seeds.rb file. This is now the default file for seeding data.
In there you can simple use your models like
User.create(:login=>"admin", :etc => :etc)
to create your data.With this approach
rake db:setup
will also seed the data as willrake db:seed
if you already have the DB.In older projects I've sometimes used a fixture (remeber to change the password straight away) with something like users.yml:
Or finally as the other guys have said you have the rake task option, hope that helps.