Why do I get the error uninitialized constant Stuff::HTTParty?

Michael Durrant picture Michael Durrant · Jun 25, 2014 · Viewed 8.4k times · Source

I have the HTTParty gem on my system and I can use it from within rails.

Now I want to use it standalone.

I am trying:

class Stuff
  include HTTParty
  def self.y
    HTTParty.get('http://www.google.com')
  end 
end
Stuff.y

but I get

$ ruby test_httparty.rb 
test_httparty.rb:2:in `<class:Stuff>': uninitialized constant Stuff::HTTParty (NameError)
        from test_httparty.rb:1:in `<main>'
07:46:52 durrantm Castle2012 /home/durrantm/Dropnot/_/rails_apps/linker 73845718_get_method
$ 

Answer

Stefan picture Stefan · Jun 25, 2014

You have to require 'httparty':

require 'httparty'

class Stuff
  include HTTParty
  # ...
end