I set up a constant in an initializer file (under /config/initializers/
myfile.rb) like this:
MYCONST = Model.find(:all).size
The problem is that rake fails to run some operations like db:migrate
or db:reset, due to the fact that my Model table doesn't exist at some
stages. Even with a "unless Model.nil?" it fails.
How can I test if the model exists to avoid error during rake? I don't
need this constant for rake tasks but only for normal execution of my
app.
I set up a constant in an initializer file (under /config/initializers/
myfile.rb) like this:
MYCONST = Model.find(:all).size
Model.count is preferred here. Model.find(:all).size loads everything
into memory first.
The problem is that rake fails to run some operations like db:migrate
or db:reset, due to the fact that my Model table doesn't exist at some
stages. Even with a "unless Model.nil?" it fails.
How can I test if the model exists to avoid error during rake? I don't
need this constant for rake tasks but only for normal execution of my
app.