a better way to initialize database ONCE when rail server starts
Posted
by Hadi
on Stack Overflow
See other posts from Stack Overflow
or by Hadi
Published on 2010-06-07T03:22:02Z
Indexed on
2010/06/07
3:32 UTC
Read the original article
Hit count: 365
ruby-on-rails
|initialization
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?
© Stack Overflow or respective owner