views:

72

answers:

0

i would like to initialize database the first time the server is started, that involve calling a class method. Given the class name is: Product

At first i put an .rb file config\initializers\init.rb as it gets automatically called. Everything works ok, until the database is deleted, and i am trying to do rake db:migrate. rake db:migrate fails saying that cannot find 'product' table.

inside init.rb = Product.populate_db

The solution i came up is:

  1. I took out init.rb
  2. do rake db:migrate
  3. put back init.rb
  4. run the server.

My rails application is mainly for reporting and the data is seeded from other application, so i have to do the above step everyday

Is there a better way to do the initialization?