What is the best way (Rails 2.0) for auto populating your models with
data.
For example if I have a category table with several types that are
pre-defined. What is the best method of auto populating the database
during deployments?
Thanks.
What is the best way (Rails 2.0) for auto populating your models with
data.
For example if I have a category table with several types that are
pre-defined. What is the best method of auto populating the database
during deployments?
Thanks.
Use a Rake task.
In Lib/tasks, make this file
import.rake
In that file, put this code:
namespace :db do
desc “Boostrap my database with default data”
task :import => :environment do
User.create :login => “admin”, :password=>“admin”,
:password_confirmation=>“admin”, email=>“[email protected]”
end
end
Then, as part of your deployment,
rake RAILS_ENV=“production” db:import
(make that part of your deployment recipe if you wish!)
Hope that helps!
On Nov 26, 2007 4:33 PM, Will M.
[email protected]
On Nov 26, 2007 4:33 PM, Will M.
[email protected] wrote:
What is the best way (Rails 2.0) for auto populating your models with
data.For example if I have a category table with several types that are
pre-defined. What is the best method of auto populating the database
during deployments?
Fixtures. RAILS_ENV=production rake db:fixtures:load
And then sometimes I just create data in the migrations, especially if
I don’t have any fixtures up to that point.
–
Greg D.
http://destiney.com/
Thanks for the quick reply guys.
you should reserve fixtures for tests. Rake is a much better tool for
production db setup.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs