Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble including httparty in ruby on rails

I've been trying to use HTTParty in my rails code

sudo gem install httparty

From the command line I can now successfully do

httparty "http://twitter.com/statuses/public_timeline.json"

When I try this in my rails app

require 'rubygems'
require 'httparty'

class FooController < ApplicationController
  include HTTParty

  def bar
    blah = HTTParty.get("http://twitter.com/statuses/public_timeline.json")
  end
end

I get the error message "no such file to load -- httparty"

I suspect there is something wrong with my environment?

like image 977
AllDayer Avatar asked Jan 07 '11 12:01

AllDayer


3 Answers

You don't need to do 'include HTTParty' inside the Controller. Just remove that and it should work. I just tested it and it worked for me. If this doesn't work for you, you should add the gem to your environment.

Usually if you use a gem inside your Rails application, you should add the following to environment.rb:

config.gem "httparty"

The gem will be available in the application now and you don't need to add 'require' inside the Controller. Also, you don't need to require RubyGems inside a Controller.

When you use Rails 3, you need to put the following inside the Gemfile:

gem "httparty"

I hope it works for you. :)

like image 66
RobinBrouwer Avatar answered Oct 31 '22 23:10

RobinBrouwer


The problem is, if you load a new gem, you have to restart the server even if you are in development.

like image 30
Harry Forbess Avatar answered Nov 01 '22 00:11

Harry Forbess


I had this same error. I tried moving the require HTTParty all over, but found, all I needed to do was restart the rails server In the end I did not need to 'require HTTParty' nor 'include' it. It just needed to be loaded into rails.

like image 4
mendokusai Avatar answered Nov 01 '22 00:11

mendokusai