rake aborted! LoadError: cannot load such file -- httparty

1.1k views Asked by At

I'm have the following in my seed.rb file:

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:

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. How can I run a HTTParty GET request in my seed.rb file? Or is the a better alternative?

1

There are 1 answers

0
hahander On
Don't know how to build task 'db:seet'   

Maybe this is a problem: try to use "rake db:seed" instead of "rake db:seet"