潇洒 - 未初始化的恒定Nokogiri异常

时间:2015-01-14 21:38:29

标签: ruby sinatra nokogiri gemfile rufus-scheduler

当我尝试开始潇洒时,我收到以下错误:

scheduler caught exception:
uninitialized constant Nokogiri
/Users/Adam/projects/ticker/jobs/sample.rb:2:in `block in <top (required)>'

我的Gemfile是:

source 'https://rubygems.org'

gem 'nokogiri'
gem 'dashing'

my jobs文件夹包含一个文件夹sample.rb:

SCHEDULER.every '2s' do
  oil_doc = Nokogiri::HTML(open("http://www.bloomberg.com/energy/"))
  a = oil_doc.css("table.std_table_module").first
  price = a.xpath("//td[3]").first.children.text
  send_event('valuation', { current: price })
end

我尝试将require 'open-uri'添加到Gemfile和sample.rb但它没有帮助!

1 个答案:

答案 0 :(得分:5)

错误消息说它并不知道有关Nokogiri的任何信息,require 'nokogiri' 是nokogiri gem中定义的模块。为了将其纳入范围,您需要添加:

sample.rb

到{{1}}(通常位于文件顶部)。