问题
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