ruby-on-rails - Rails NoMethodError(Hyperclient:Module 的未定义方法“新”)
问题描述
这是一个相当“新手”的问题,但我一直在搜索,似乎找不到任何东西来解决在我的模型方法之一中使用超级客户端在 Rails 应用程序中出现的错误。
每当我运行时,rails c
我都会收到错误
NoMethodError (undefined method `new' for Hyperclient:Module)
在我的宝石文件中
gem "hyperclient"
——跑了bundle install
在模型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
我查看了hyperclient上的文档,发现他们确实有 .new 的方法(也在他们的示例中),所以我知道这是我做错了,但我不确定还有什么可以尝试的?
在终端中打开 irb 时,代码确实有效。
解决方案
您还没有在您的文件中指定任何版本,Gemfile
因此可能会发生Bundler
不会安装最新版本的情况,这就是我猜这里可能发生的情况。
您可以通过执行以下操作检查安装了哪个版本:
cat Gemfile.lock | grep hyperclient
您在这里至少有两个选择:
1)
bundle update hyperclient
- 这应该将您更新Gemfile.lock
到最新版本
2)
bundle remove hyperclient
bundle add hyperclient --version "0.9"
- 这将更新您的 Gemfile,然后运行bundle install
它将重新生成您的Gemfile.lock
建议使用第二个选项,因为始终为您使用的 gem 指定版本是一个很好的做法。
推荐阅读
- node.js - ExpressJS 在不同的路由中调用另一个路由
- google-apps-script - 谷歌应用脚本:是否可以在发送共享通知的同时限制文件的共享设置?
- c++ - 如何在 MacOS 上构建和链接 Boost.Serialization
- django - 即使使用媒体 url 和媒体根,Django 模板图像也不会显示
- javascript - React - 不必要的渲染
- python - 将 txt 文件中的条目导入列表。格式问题
- amazon-dynamodb - 是否可以在 dynamodb 查询的排序键中使用正则表达式?
- node.js - 无响应的上传按钮 React.js 和 Node.js 构建
- javascript - 如果我在 firestore 上设置了 ignoreUndefinedProperties 设置,则获取“FirebaseError:缺少或不足的权限”
- docker - 将带有初始化的 docker run 命令翻译为多容器 k8s pod 或 compose