ruby-on-rails - RoR 将哈希传递给对象初始化导致“没有将符号隐式转换为整数”
问题描述
虽然我理解这个错误的含义,但我似乎没有做任何可能导致它的错误。假设我有 2 个文件:
auths_controller.rb:
def index
config = GmailOauth::Application.credentials.google[:web].stringify_keys!
gmail_client = Gmail::GmailClient.new(config)
end
config 只是一个带有符号的哈希类,在这个例子中,我什至对键进行了字符串化,这样我就可以像这样访问它们:config["client_id"]
这是此文件中“puts config”的输出:
{"client_id"=>"xxx.apps.googleusercontent.com", "project_id"=>"xxx", "auth_uri"=>" https://accounts.google.com/o/oauth2/auth ", "token_uri "=>" https://accounts.google.com/o/oauth2/token ", "auth_provider_x509_cert_url"=>" https://www.googleapis.com/oauth2/v1/certs ", "client_secret"=>" xxx"}
都很好,对吧?这是 GmailClient 文件:
module Gmail
class GmailClient
def initialize(config)
puts config # this already throws the error!
exit
我不明白为什么只通过方法调用我得到错误“没有将符号隐式转换为整数”
任何帮助将不胜感激
解决方案
推荐阅读
- google-chrome-extension - WebPaint 等 Chrome 扩展程序如何工作?
- jolt - 使用 JOLT 进行 JSON 转换
- python - 并发调度大量 DAG 时出现重复条目错误
- php - 如何在 PHP 中使用 str_replace 使其不影响 html 标签和属性
- arrays - 如何在循环中收集用户输入,然后使用循环访问该输入?
- discord - 如何添加前缀 discord.js
- python - Django - 如何从具有外键的模型中获取所有项目?
- mongodb - mongodb客户端的“无法读取未定义的属性'替换'”
- push-notification - 我需要创建一个不需要 FCM/GCM 或 APN 的需要推送通知的 Web 应用程序
- node.js - 在 MongoDB (Mongoose) 中使用事务创建链表