Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uninitialized constant problem in Heroku / Sinatra #353

Closed
reedstonefood opened this issue Feb 4, 2020 · 3 comments
Closed

Uninitialized constant problem in Heroku / Sinatra #353

reedstonefood opened this issue Feb 4, 2020 · 3 comments

Comments

@reedstonefood
Copy link

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.

@judofyr
Copy link
Collaborator

judofyr commented Feb 6, 2020

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

@judofyr
Copy link
Collaborator

judofyr commented Feb 6, 2020

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?

@reedstonefood
Copy link
Author

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants