Sinatra: Undefined method 'run' when using

2019-09-16 15:14发布

I have modular style sinatra app, with the following line near the end, so that it can be run standalone:

  # ... all code before this omitted
  run! if __FILE__ == $0

end
# This is the end of the file

When I run this app with ruby app.rb it works fine, and webrick starts up.

However, if I run it instead with bundle exec ruby app.rb I get this error:

>bundle exec ruby app.rb
C:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.4/lib/sinatra/base.rb:1488:in `start_server': undefined method `run' for HTTP:Module (NoMethodError)
        from C:/Ruby200/lib/ruby/gems/2.0.0/gems/sinatra-1.4.4/lib/sinatra/base.rb:1426:in `run!'

What's causing this error?

1条回答
孤傲高冷的网名
2楼-- · 2019-09-16 15:57

Explicitly set your webserver, e.g.

set :server, 'thin'

and make sure you add whatever server you’re using to your Gemfile, e.g.

gem 'thin'
查看更多
登录 后发表回答