Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby error: cannot load such file -- rest-client

I am using Ruby on Rails 4.

I am trying to

require 'rest-client'

in my controller so that I can parse the login information I am getting from a form and send it to an API.

I can verify that the gem is installed and is also in my Gemfile on the application root.

However, it is still throwing the "cannot load such file -- rest-client " when I try to require the file in my controller.

I have googled the error and most of the answers I saw were either the gem wasn't installed, wasn't in the Gemfile, or a combination of both those. Neither is the situation here.

Is my controller unable to access the rest-client gem for some reason? I have to use rest-client because it is required in the API.

This is the line I used to install the gem:

gem install rest-client

This is the homepage of the gem: https://github.com/archiloque/rest-client
Which just redirects you to https://github.com/rest-client/rest-client

I should also note that it works fine when I wasn't using the code in a Rails project but just running the commands in the Terminal.

like image 845
Jerrod Avatar asked Jul 31 '13 14:07

Jerrod


2 Answers

Assuming you're using https://github.com/rest-client/rest-client (since you didn't specify), your require line should be

require 'rest-client'

according to the README. Also, make sure you restart your rails server after adding the gem to your Gemfile and running bundle.

like image 195
deefour Avatar answered Sep 18 '22 03:09

deefour


Run the following command in your terminal:

gem install rest-client

and use require 'rest-client'. No need to change to rest_client.

like image 37
akvenk Avatar answered Sep 21 '22 03:09

akvenk