문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

Run the following command in your terminal:

gem install rest-client

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

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

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.

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!

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top