Ruby 错误:无法加载此类文件——rest-client

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17973872/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 22:27:14  来源:igfitidea点击:

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

ruby-on-railsrubyrest-client

提问by Jerrod

I am using Ruby on Rails 4.

我正在使用 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.

在我的控制器中,以便我可以解析我从表单中获取的登录信息并将其发送到 API。

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

我可以验证 gem 是否已安装并且也在应用程序根目录的 Gemfile 中。

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

但是,当我尝试在我的控制器中要求该文件时,它仍然抛出“无法加载此类文件 -- rest-client ”。

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.

我用谷歌搜索了错误,我看到的大多数答案要么是 gem 没有安装,要么不在 Gemfile 中,要么是两者的组合。这里的情况也不是。

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.

我的控制器是否由于某种原因无法访问 rest-client gem?我必须使用 rest-client,因为它在 API 中是必需的。

This is the line I used to install the gem:

这是我用来安装 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

这是 gem 的主页:https: //github.com/archiloque/rest-client
它只是将您重定向到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.

我还应该注意,当我不在 Rails 项目中使用代码而只是在终端中运行命令时,它工作正常。

回答by deefour

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

假设您使用的是https://github.com/rest-client/rest-client (因为您没有指定),您的require线路应该是

require 'rest-client'

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

根据自述文件。另外,请确保在将 gem 添加到您的Gemfile并运行bundle.

回答by akvenk

Run the following command in your terminal:

在终端中运行以下命令:

gem install rest-client

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

并使用require 'rest-client'. 无需更改为rest_client。

回答by Salomanuel

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

在我的情况下,该线程中的所有解决方案都
没有起作用,而是直接在以下内容中添加 gem Gemfile

 gem 'rest-client'

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

关闭rails server,退出rails console并运行后bundle install
我再次打开rails console,这次require 'rest-client'工作完美

回答by Margaret Munyite

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

首先确保你已经在你的 gem 文件上安装了gem 'rest-client', ~> 1.8.0。运行 bundle install 然后require 'rest_client'. 这对我有用。

回答by schro's cat

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:

对我来说,这是 bundle 的问题(我以为我已经安装了)。剧透警报,我没有,这就是我修复它的方式。我在运行 OS X Yosemite 的 Mac 上,我的终端版本是 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.

错误:执行 gem 时 ... (Gem::FilePermissionError) 您没有 /Library/Ruby/Gems/2.0.0 目录的写权限。

Finally, change your require line from:

最后,将您的 require 行从:

require 'rest-client'

to

require 'rest_client'

Then run your code!

然后运行你的代码!

回答by revolver

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

尝试require 'rest_client',而不是require 'rest-client'