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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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=>"admin-FBj3rGVNSac4Q++5jOxPmw@public.gmane.org"
# other cool ruby code goes here
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 Merydith
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
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?
>
> Thanks.
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On Nov 26, 2007 4:33 PM, Will Merydith <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 Donald http://destiney.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for the quick reply guys. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
bphogan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Nov-27 01:28 UTC
Re: Best Practice:: Filling Models With Data
you should reserve fixtures for tests. Rake is a much better tool for production db setup. On 11/26/07, Greg Donald <gdonald-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On Nov 26, 2007 4:33 PM, Will Merydith <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > 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 Donald > http://destiney.com/ > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---