Sinatra: Undefined method 'run' when using bundle exec ruby app.rb

冷暖自知 提交于 2020-02-08 05:23:03

问题


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:


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'


来源:https://stackoverflow.com/questions/22785807/sinatra-undefined-method-run-when-using-bundle-exec-ruby-app-rb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!