Uninitialized constant problem in Heroku / Sinatra
reedstonefood opened this issue · 3 comments
There is a long-standing problem when Heroku and Sinatra run together with Tilt version 2.0, that manifests itself as
uninitialized constant Tilt::SomeClassName (NameError)
See this stackoverflow post which suggests downgrading to Tilt version 1. This isn't a great long-term solution and it would be great to have a more permanent fix.
I'm coming up against this error in my erb file where I have the line
<% Template::TEMPLATES.each do
and it complains that Template is an uninitialized constant. It works fine when I run locally.
Any ideas? I'm unsure if the bug lies with Tilt, Sinatra or Heroku but given the error comes from Tilt it seems a good place to start.
Hm. Do you have an old version of Sinatra? Tilt::CompileSite
hasn't been used in a while.
If that's the only error you have, then you should be able to fix it by adding the following somewhere:
require 'tilt'
module Tilt::CompileSite; end
Or, if the error is about Tilt::CompileSite
(as the linked StackOverflow is) then the code in the previous comment would fix it.
If it's about "Template is an uninitialized constant" then it could be caused by having different versions of Ruby locally and on Heroku which has slightly different constant lookup rules. Could you try to refer to it using a top-level constant reference? ::Somewhere::Template::TEMPLATES
?
it could be caused by having different versions of Ruby locally
Thanks, I tried that but it didn't help...
Could you try to refer to it using a top-level constant reference?
::Somewhere::Template::TEMPLATES?
This did, though! It's working fine now! Thanks a lot :)