Ruby on Rails Tuesday, February 18, 2014


On Tue, Feb 18, 2014 at 9:32 PM, Luca Fuhl <lists@ruby-forum.com> wrote:
But how does derive from ActiveRecord solve my problem? I want to
instance an object of the model i generated and that in an file that
isn't a controller, since i do this only one time.

The inheritance from ActiveRecord will allow you to add new objects easily. Create a custom rake task in lib/tasks file.

Here you can create the model objects using the data from the website and call create on each model object which would save the record in the DB. You can call this rake task immediately after rake db:migrate which would populate the database.

Also, there are some gems which will create a seeds.rb file from an already populated database. Then you don't need to crate a custom rake task and call rake db:seed

Thanks,
Ganesh

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CALFmRoFxuc5SmLxxcsWLHWDVY3WHvFipfW_nFJeMYoUHfdEUHg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment