【问题标题】:Yelp ruby gem on HerokuHeroku 上的 Yelp 红宝石宝石
【发布时间】:2015-07-23 22:45:34
【问题描述】:

我在 yelp.rb 中有这个代码作为初始化器:

Yelp.client.configure do |config|
 config.consumer_key = ENV['config.consumer_key']
 config.consumer_secret = ENV['config.consumer_secret']
 config.token = ENV['config.token']
 config.token_secret = ENV['config.token_secret']
end

我有一个 yelp.yml 文件,它可以加载所有这些内容,它在开发中效果很好。

只要我将它推送到 heroku(我的所有密钥也都设置在 Heroku 中,并且三重验证没有拼写错误)我收到此错误 'Yelp::Error::MissingAPIKeys: You're missing an API key '

我在 Rails C 中运行了开发代码(见下文),它通过了,在 Heroku 端的 Rails c 中运行了完全相同的代码,我得到了那个错误。我什至在不使用 ENV 的情况下进行了尝试,并使用了确切的 api 密钥和相同的错误。

client = Yelp::Client.new({  
  consumer_key = ENV['config.consumer_key'],
  consumer_secret = ENV['config.consumer_secret'],
  token = ENV['config.token'],
  token_secret = ENV['config.token_secret'] })

生产和开发之间有什么不同?

更新: 搞定了... 我能够让它以这种方式工作......

def index
      current_user.zip_code.present? ? @zip = current_user.zip_code :     @zip = "94101"
      parameters = { term: 'auto repair', limit: 9 }
      @search = client.search(@zip, parameters)
  end

  private
  def client
     @client ||= Yelp::Client.new({ consumer_key: ENV['config.consumer_key'],
      consumer_secret: ENV['config.consumer_secret'],
      token: ENV['config.token'],
      token_secret: ENV['config.token_secret']
    })
  end

【问题讨论】:

    标签: ruby-on-rails ruby heroku gem yelp


    【解决方案1】:

    运行heroku config --app app-name 以检查配置变量是否设置正确,如果看起来正确。然后尝试使用 heroku run rails console --app app-name 在 Heroku 上运行 rails 控制台,以检查 Yelp::Client 是否正确加载了 env

    如果您只遵循gem readme 中提供的ENV 命名约定,则可以完全避免此问题。

    Yelp.client.configure do |config|
      config.consumer_key = YOUR_CONSUMER_KEY
      config.consumer_secret = YOUR_CONSUMER_SECRET
      config.token = YOUR_TOKEN
      config.token_secret = YOUR_TOKEN_SECRET
    end
    

    【讨论】:

    • 太棒了。也能说出问题所在,有兴趣更好地了解问题。或者更好的是添加它作为这个问题的答案。
    猜你喜欢
    • 1970-01-01
    • 2019-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多