问题描述
我使用 Mechanize 作为命令行实用程序编写了一个简单的Web搜寻器.然后,我决定使用 Sinatra 创建Web应用程序,但是在尝试运行本地Web服务器时陷入了该错误:
I've writter a simple web crawler using Mechanize as a command-line utility. Then I decided to create web app with Sinatra, but got stuck with this error when trying to run the local webserver:
/home/nazar/.rvm/gems/ruby-2.0.0-p195/gems/sinatra-1.4.2/lib/sinatra/base.rb:1569:in `run!': undefined method `run' for HTTP:Module (NoMethodError)
from /home/nazar/.rvm/gems/ruby-2.0.0-p195/gems/sinatra-1.4.2/lib/sinatra/main.rb:25:in `block in <module:Sinatra>'
源代码非常简单:
require 'sinatra'
require 'mechanize'
get '/' do
# mechanize stuff
end
我已经进行了一些调查,并设法发现2颗宝石可以单独工作,但仅将它们结合使用会导致问题.谁能指出问题出在哪里?
I've gone through some investigation and managed to find out that 2 gems work fine separately, but only combining them causes the issue. Can anyone point out what the problem might be?
推荐答案
很可能您正在覆盖诸如get与mechanize之类的方法.尝试将您的Sinatra应用程序包装到应用程序类中.这样可以解决问题.
Most probably you are are overriding methods like get with mechanize. Try to wrap your Sinatra application into an application class. That may resolve the issue.
require 'sinatra/base'
class MyApp < Sinatra::Base
get '/' do
# mechanize stuff
end
end
在 Sinatra文档.
这篇关于机械化Sinatra冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!