[英]Rails NoMethodError (undefined method `new' for Hyperclient:Module)
This is quite a 'newbie' question but I've been searching and can't seem to find anything to solve an error with using hyperclient in a rails app, in one of my Model's methods.这是一个相当“新手”的问题,但我一直在搜索,似乎找不到任何东西来解决在我的模型方法之一中使用超级客户端在 Rails 应用程序中出现的错误。
Whenever I run rails c
I get the error NoMethodError (undefined method `new' for Hyperclient:Module)
每当我运行
rails c
,我都会收到错误NoMethodError (undefined method `new' for Hyperclient:Module)
In my gemfile在我的宝石文件中
gem "hyperclient"
-- ran bundle install
-- 运行
bundle install
in model app/models/artwork.rb在 model app/models/artwork.rb
class Artwork < ApplicationRecord
require "hyperclient"
def self.test_artsy
api = Hyperclient.new('https://api.artsy.net/api') do |api|
puts api
end
end
end
I've looked at the docs on hyperclient and have seen that they do have a method for.new (also on their examples) so I know it's something I've done incorrectly but I'm not sure what else to try?我查看了 hyperclient 上的文档,发现他们确实有一个 for.new 方法(也在他们的例子中)所以我知道这是我做错了,但我不确定还有什么可以尝试的?
The code did work when opening irb in the terminal.在终端中打开 irb 时,代码确实有效。
You haven't specified any version in your Gemfile
so it might happen that Bundler
will not install the latest version and that's what I am guessing might happened here.您没有在
Gemfile
中指定任何版本,因此Bundler
可能不会安装最新版本,这就是我猜这里可能发生的情况。
You can check which version is installed by doing: cat Gemfile.lock | grep hyperclient
您可以通过执行以下操作检查安装了哪个版本:
cat Gemfile.lock | grep hyperclient
cat Gemfile.lock | grep hyperclient
You have at least two options here:您在这里至少有两个选择:
1) bundle update hyperclient
- this should update your Gemfile.lock
to the latest version 1)
bundle update hyperclient
超级客户端 - 这应该将您的Gemfile.lock
更新到最新版本
2) bundle remove hyperclient bundle add hyperclient --version "0.9"
- this will update your Gemfile and then run bundle install
that will regenerate your Gemfile.lock
2)
bundle remove hyperclient bundle add hyperclient --version "0.9"
- 这将更新您的 Gemfile,然后运行bundle install
重新生成您的Gemfile.lock
The second option is recommended since it is a good practice to always specify version for the gems you are using.建议使用第二个选项,因为始终为您使用的 gem 指定版本是一个很好的做法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.