Welcome to Working With Rails


Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
Populate default data for new account
4 Posts
Populate default data for new account

I need a way to populate default data when a new account is created.

I've been using seed_fu with fixtures YAML files to populate the default data for my app but this isn't working on an individual basis.

Basically the account is created and I need it to add some services and testimonials using the new account id.

Any ideas on the best way to set this up?

You can create any data in after_create method of your model.


I currently have an after_create: populate_defaults method

My question is how do I call the scritp to populate the data in the models and what does that script look like?

I currently have the following:

def populate_defaults add_defaults self.id end

Does anyone have a solution for this? I'd like to be able to call a file and load that data either with SQL or just activerecord create calls (creating about 9 records into different tables).

I am just unsure how to exactly load a file that will perform these actions. Where should I put the file? How do I reference it? Is it better to use SQL commands or ActiveRecord creates like the following:

Service.create( :title => "testing", :account_id => self.id, :active => 1, :body => "testing")

Any additional help is appreciated. Thank you.

4 Posts
Login to add your message