I am perplexed by something that isn't actually a practical problem - just a conceptual conundrum - about deploying a Sinatra app on Heroku.
I have two apps, identical in just about every respect, except that one puts most of its logic in a file that does not contain the Sinatra::Base class and uses a 'require otherfilename' to pick up the logic it needs. That Sinatra:Base class is named Kincalc.
For the app with all the logic in one file (that is, the same file that contains the Sinatra:Base class), in my config.ru file, the last line reads "run Sinatra::Application" and it launches fine. But in the other app, if I include that as the last line, the app uploads properly and says it was "deployed to Heroku" but it brings up a "Not found" message. When I have the last line read 'run Kincalc', it loads fine.
I have checked this back and forth and there is nothing different about how these two apps are built, except for the fact that one uses a second file for the logic (which is also at root). Why should this be a problem, or is this really the problem? When I try to put the second file (the one without the Sinatra class) in a separate lib folder, it still works when I call the class name but not when I call "Sinatra::Application."
Code at top level will be delegated to
Sinatra::Application
, so this would be a scenario for running a classic application:If you define a modular app, you would run it like this:
Now I assume what you are trying to do is this:
The behavior you experience (getting a 404 File Not Found) is actually correct, as
require
does not care about the lexical scope it is called in. Check out the following exampleThe resulting output should be:
So, if you want to use one modular application, you should do something like this:
Or open the class again:
Or you could actually have
otherfilename.rb
make it's definitions onSinatra::Application
and utilize that inKincalc
.Or you could change where top level DSL methods are delegated to: