首页 > 解决方案 > 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

我不明白为什么只通过方法调用我得到错误“没有将符号隐式转换为整数”

任何帮助将不胜感激

标签: ruby-on-railsrubysymbols

解决方案


推荐阅读