简体   繁体   English

耙子流产了! LoadError:无法加载此类文件— httparty

[英]rake aborted! LoadError: cannot load such file — httparty

I'm have the following in my seed.rb file: 我的seed.rb文件中包含以下内容:

require 'httparty'
require 'nokogiri'
require 'awesome_print'

BASE_URL    = "http://www.legacy.com/funeral-homes/"
URL_PATH    = "directory/"

def get_states(key, value)
  arry = []
  i = 1
  while i <= value do 

    response = HTTParty.get(BASE_URL + URL_PATH + "#{key}" + "?page=#{i}")
    page = Nokogiri::HTML(response.body)

    rows = (page.css("div.fhlistitem").select { 
      |e| !e.content.squeeze(" ").strip.empty? }).map { 
      |e| [e.css('div.fhname a').first['href'], 
           e.content.squeeze("").strip.split("\r\n").compact ]
    }

      rows.each do |row|
        row[1].delete(" ")

        hash = {
          "name"     => row[1][0].strip,
          "address"  => row[1][1].strip,
          "phone"    => row[1][4].nil? ? "" : row[1][4].strip,
          "email"    => row[1][5].nil? ? "" : row[1][5].strip,
          "license"  => row[1][6],
          "url"      => row[0]
        }

        arry << hash

      end

      i += 1

    end

  arry

end

fhs = get_states("alaska", 4)

fhs.each do |fh|
  FuneralHome.create( 
    name:       fh["name"], 
    address:    fh["address"], 
    phone:      fh["phone"], 
    email:      fh["email"], 
    license:    fh["license"], 
    url:        fh["url"], 
  )
end

When I run rake db:seed I get the following error: 当我运行rake db:seed时,出现以下错误:

WARN: Unresolved specs during Gem::Specification.reset:
  mini_portile (~> 0.6.0)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
rake aborted!
Don't know how to build task 'db:seet'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/task_manager.rb:62:in `[]'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:149:in `invoke_task'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `each'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `block in top_level'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:115:in `run_with_threads'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:100:in `top_level'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:78:in `block in run'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:75:in `run'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.3.2/bin/rake:33:in `<top (required)>'
/usr/local/bin/rake:23:in `load'
/usr/local/bin/rake:23:in `<main>'

I'm not sure how to interpret the error. 我不确定如何解释该错误。 I'm requiring 'httparty' in the file. 我在文件中需要“ httparty”。 How can I run a HTTParty GET request in my seed.rb file? 如何在seed.rb文件中运行HTTParty GET请求? Or is the a better alternative? 还是更好的选择?

Don't know how to build task 'db:seet'   

也许这是一个问题:尝试使用“ rake db:seed”代替“ rake db:seet”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM