Вопрос

I'm deploying my Rails app on Heroku (Cedar), and there were 3 options about precompiling my assets I could choose from, and I chose the option where Heroku precompiles my assets on deployment.

When I pushed, I got an error that it cannot access my database (during precompiling). So, how to make Rails not connect to the database during precompiling? I don't know why it's set in the first place, because I can't imagine a scenario where precompiling would need access to the database.

I saw somewhere a solution to disable initializing the application on precompiling, which is achieved by adding the following into the application.rb (setting it in the environments/production.rb doesn't work):

config.assets.initialize_on_precompile = false

I tried adding this line, and it works, but I don't know if it is a good solution. Wouldn't this make some plugins you would potentially use for the assets not load during precompiling, thus affecting the end result?

Это было полезно?

Решение

If you enable Heroku Labs (http://devcenter.heroku.com/articles/labs-user-env-compile) you can have access to your Db at deployment time which works great.

Do you use Devise? That's usually a culprit for DB access on precompiling assets incidentally.

Другие советы

What you're doing is the correct way. If you don't use models / anything else which is actually accessing the database in your assets then you have no need for it. The only time you'd need to have your app initialized is if you were doing things like this: (Completely contrived example, but you can see what I'm getting at)

/* In some css file */
.some_class{
    #{User.find(1).avatar_url}
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top