Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly was initialize_on_precompile used for?

I'm having trouble understanding what initialize_on_precompile was used for. What exactly did it mean for it to be false (especially as it relates to Heroku)? What did it mean for it to be true?

Apologies if this question is too broad/vague, but I can't seem to find the answer anywhere.

like image 886
user7392373 Avatar asked Jan 09 '17 01:01

user7392373


1 Answers

This option was available till Rails 3.x as when you run rake assets:precompile it initializes the application and tries to connect to the database. So setting this option to false prevents it. So if you have any issues in connection to the database rake assets:precompile won't work and fail this option ensures that it will work.

From Rails Git Repo:

The initialize_on_precompile change tells the precompile task to run without invoking Rails. This is because the precompile task runs in production mode by default, and will attempt to connect to your specified production database. Please note that you cannot have code in pipeline files that relies on Rails resources (such as the database) when compiling locally with this option.

In Rails 4.x this option has been removed and is no longer required. Rails 4 now always loads initializers and the database configuration before precompiling assets

Source of Commit: https://github.com/rails/rails/commit/2d5a6de

like image 119
Deepesh Avatar answered Nov 05 '22 00:11

Deepesh