Sinatra not running from ./app (old style of routes)

13 views
Skip to first unread message

Tim Uckun

unread,
Sep 27, 2017, 7:09:41 AM9/27/17
to sinatrarb
I have an app and it runs fine if I do rackup or puma but it doesn't run when I do ruby app.rb I tried putting 

require 'sinatra' 

run Sinatra::Application on the bottom but it says run is not defined.


This used to work but I have no idea what I did to make it stop working.

The reason I am asking is that puma does not run inside of a docker container for some reason giving me the error "no app specified".

Thanks in advance for your help.


Mike Pastore

unread,
Sep 27, 2017, 9:57:33 PM9/27/17
to sinatrarb
On Wednesday, September 27, 2017 at 6:09:41 AM UTC-5, Tim Uckun wrote:
I have an app and it runs fine if I do rackup or puma but it doesn't run when I do ruby app.rb I tried putting 

require 'sinatra' 

run Sinatra::Application on the bottom but it says run is not defined.

If you're writing an app in classic mode, you don't need to run it at the bottom of the file; it runs automatically if invoked directly (i.e. ruby app.rb). If you're writing an app in modular mode, you can put a run! at the bottom of the class to run it automatically if it's invoked directly:

# app.rb
class MyApp < Sinatra::Application
 
get '/' do
   
'Hello, world!'
 
end

  run
! if $0 == __FILE__
end

So maybe that's what you're thinking of?

Tim Uckun

unread,
Sep 28, 2017, 12:50:56 AM9/28/17
to sina...@googlegroups.com

If you're writing an app in classic mode, you don't need to run it at the bottom of the file; it runs automatically if invoked directly (i.e. ruby app.rb). If you're writing an app in modular mode, you can put a run! at the bottom of the class to run it automatically if it's invoked directly:


I have it in the classic mode but for some reason it doesn't run when I invoke it that way.


Mike Pastore

unread,
Sep 28, 2017, 1:44:23 PM9/28/17
to sinatrarb
On Wednesday, September 27, 2017 at 11:50:56 PM UTC-5, Tim Uckun wrote:
I have it in the classic mode but for some reason it doesn't run when I invoke it that way.

Are you "running" the file that contains the require "sinatra" (or the Bundler.require) or are you running a file that requires that file? I'm guessing the latter. The autorun feature only works if you run the file that contains the require "sinatra" (or the Bundler.require). 
Reply all
Reply to author
Forward
0 new messages