我正在使用设计和 bitbucket api gem,并且我的 ApplicationController 中有一个方法,它创建一个实例,以便我可以进行 API 调用。为此,它会尝试从 current_user 读取令牌和密码。
这适用于硬编码的令牌和秘密字符串,我也可以puts current_user.inspect
在 do 块之前执行此操作,并且一切正常。我也确定 bb_token 和 bb_secret 存在(我可以单独调用 puts )。
但是一旦我尝试创建我的 bitbucket 实例,它就无法再读取 current_user 了。有任何想法吗?
class ApplicationController < ActionController::Base
protect_from_forgery
helper_method :current_user
def bitbucket
puts "token----------"
puts current_user
@bitbucket = BitBucket.new do |config|
config.oauth_token = current_user.bb_token # replaceing this with hardcoded string works
config.oauth_secret = current_user.bb_secret # replaceing this with hardcoded string works
config.client_id = 'xx'
config.client_secret = 'yy'
config.adapter = :net_http
end
end
end
和错误:
NameError (undefined local variable or method `current_user' for #<BitBucket::Client:0x007fbebc92f540>):
app/controllers/application_controller.rb:12:in `block in bitbucket'
app/controllers/application_controller.rb:11:in `bitbucket'