Ruby error: cannot load such file -- rest-client
Asked Answered
S

7

19

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.

Squiggle answered 31/7, 2013 at 14:56 Comment(3)
According to the github documentation you ned to do require 'rest_client' with an underscore.Damnatory
I made that change with the same resultant error.Squiggle
It shows up in the bundle. Restarting the server did it. Thanks Abe.Squiggle
L
20

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.

Lawler answered 31/7, 2013 at 14:58 Comment(3)
This is no more applicableHelicograph
Well it was posted nearly 3 years ago. Feel free to suggest an edit if you have an alteration to make it relevant.Lawler
Well you can't do a 1 character edit :) , please change this from require 'rest_client' to require rest-clientHelicograph
A
8

Run the following command in your terminal:

gem install rest-client

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

Aerator answered 30/5, 2016 at 7:6 Comment(0)
V
6

in my case, none of the solutions in this thread worked
what did work, was to add the gem directly in the Gemfile:

 gem 'rest-client'

after closing the rails server, exiting rails console and running bundle install,
I opened again the rails console and this time require 'rest-client' worked flawlessly

Valma answered 6/9, 2017 at 16:42 Comment(0)
M
1

For me it was an issue with bundle (which I thought I had installed). Spoiler alert, I didn't, and this is how I fixed it. I'm on a Mac running OS X Yosemite and my terminal version is Darwin Kernel Version 14.3.0:

cd
gem install bundler 

or

cd
sudo gem install bundler

If you get something along the lines of the following error:

ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

Finally, change your require line from:

require 'rest-client'

to

require 'rest_client'

Then run your code!

Majewski answered 25/6, 2015 at 21:38 Comment(0)
I
0

First ensure you have installed gem 'rest-client', ~> 1.8.0 on your gem file. Run bundle install and then require 'rest_client'. This worked for me.

Isochroous answered 22/5, 2015 at 8:12 Comment(0)
T
0

Add require 'rest-client' to your top of controller and restart server

Tonguelash answered 3/1 at 8:3 Comment(2)
please add sample code which helps others also to understand.Akkadian
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Dodecahedron
E
-1

Try require 'rest_client', instead of require 'rest-client'

Erupt answered 31/7, 2013 at 14:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.