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:
- I took out init.rb
- do rake db:migrate
- put back init.rb
- 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?