Error Deploying to Production on Heroku
Author: John on December 30, 2014
I have been making progress with a personal application that I am working on. In the early days of development, I had deployed a version of the application to Heroku - and it worked fine at that time. Fast forward 6 months or so and lots of changes. I deployed to Heroku and received an error when trying to view the website:
heroku logs 2014-12-25T01:17:54.017424+00:00 heroku[web.1]: State changed from starting to crashed 2014-12-25T01:17:55.195360+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=example.herokuapp.com request_id=0c587d48-ac93-4bce-91bc-9d2de62e6a86 fwd="126.96.36.199" dyno= connect= service= status=503 bytes= 2014-12-25T01:17:55.719076+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=example.herokuapp.com request_id=d586d82a-8c27-4f57-b5f1-cf2b55c155d7 fwd="188.8.131.52" dyno= connect= service= status=503 bytes=
That error made no sense to me. What the heck, I know the favicon.ico file exists, and why can't I get to the root path? So I went to the rails console via heroku:
heroku run rails console Running `rails console` attached to terminal... up, run.9397 /app/app/models/connexion.rb:1:in `<top (required)>': superclass mismatch for class Nurny (TypeError) from /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `require' from /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `block in require'
Note that I am substituting my real class name with a bogus one, 'Nurny', for this example.
Ok, now I get an error that looks like a real error, though I didn't understand it. Luckily this all occurred the night before our weekly morning Code and Coffee. So I brought the issue up and Micah gave me a hand for a while, having me try different things.
The conflict only shows when trying to run in a production environment. I had a model for 'Nurny' that had a class defined of Nurny. However, I also have a model concern, for queries, with a class of 'Nurny' which was the cause of the issue.
So, now how can I fix this? I tried a simple rename of the concern, changing the line:
BEFORE class Nurny AFTER class NurnyQry
But that spurred a flurry of new problems. Luckily I found another solution while thinking through this issue. Why did the app work fine in a development rails environment, but not in production. Now I must confess I'm not sure if my solution will have a profound negative effect, but so far I have not encountered any issues. The solution lies in the config/environments/production.rb file:
BEFORE: config.eager_load = true< AFTER: config.eager_load = false
And that simple configuration change fixed my issue!
Learn Something New Every Day
Last Edited by: John on November 11, 2015