Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails未定义方法_Ruby On Rails_Yahoo - Fatal编程技术网

Ruby on rails Rails未定义方法

Ruby on rails Rails未定义方法,ruby-on-rails,yahoo,Ruby On Rails,Yahoo,我正在尝试使用雅虎登录,并试图获取令牌,但无法这样做。我遵循这一点 此行中出现错误“访问\u令牌=身份验证信息[:凭据][:令牌]” 未定义nil:NilClass的方法“[]” [omniauth.rb] [家庭控制器] 您应该使用实例变量或将所有实例变量包装到model方法中。在这里,您可以看到不同的oauth集成(linkedin、twitter、gcal)。我不知道您的用例,但我出于不同的原因将数据保存到数据库中。显示配置文件属性所需的Linkedin/twitter数据以及g

我正在尝试使用雅虎登录,并试图获取令牌,但无法这样做。我遵循这一点


此行中出现错误“访问\u令牌=身份验证信息[:凭据][:令牌]
未定义nil:NilClass的方法“[]”


[omniauth.rb]


[家庭控制器]


您应该使用实例变量或将所有实例变量包装到model方法中。在这里,您可以看到不同的oauth集成(linkedin、twitter、gcal)。我不知道您的用例,但我出于不同的原因将数据保存到数据库中。显示配置文件属性所需的Linkedin/twitter数据以及gcal令牌对于在新请求时刷新访问非常重要

社会控制者

def create
  raise :test
  begin
    @profile = current_user.profile
    @social = @profile.socials.find_or_create_from_auth_hash(auth_hash)
    if auth_hash.provider == "google_oauth2"
      flash[:success] = "Your faskyn calendar is now connected to your google calendar!"
    else  
      flash[:success] = "#{@social.provider.camelize} account was successfully updated!"
    end
  rescue
    flash[:warning] = "There was an error while trying to authenticate you!"
  end
  redirect_to edit_user_profile_path(current_user)
end

private

def auth_hash
  request.env['omniauth.auth']
end
社交网站

def self.find_or_create_from_auth_hash(auth_hash)
  calendar not to update the profile
  social_acc = where(provider: auth_hash.provider).first_or_create
  if auth_hash.provider == "google_oauth2"
  social_acc.update(
    uid: auth_hash.uid,
    email: auth_hash.info.email,
    token: auth_hash.credentials.token,
    refresh_token: auth_hash.credentials.refresh_token,
    expires_at: Time.at(auth_hash.credentials.expires_at).to_datetime)
  social_acc
else
  social_acc.update(
    #no first_name, last_name and phone for twitter
    uid: auth_hash.uid,
    token: auth_hash.credentials.token,
    secret: auth_hash.credentials.secret,
    picture_url: auth_hash.info.image,
    location: auth_hash.info.location,
    description: auth_hash.info.description,
    first_name: auth_hash.info.first_name || nil,
    last_name: auth_hash.info.last_name || nil,
    phone: auth_hash.info.phone || nil,
    page_url:   case social_acc.provider
                when 'twitter' then auth_hash.info.urls.Twitter
                when 'linkedin' then auth_hash.info.urls.public_profile
                end
    )
  social_acc
end

您应该使用实例变量或将所有实例变量包装到model方法中。在这里,您可以看到不同的oauth集成(linkedin、twitter、gcal)。我不知道您的用例,但我出于不同的原因将数据保存到数据库中。显示配置文件属性所需的Linkedin/twitter数据以及gcal令牌对于在新请求时刷新访问非常重要

社会控制者

def create
  raise :test
  begin
    @profile = current_user.profile
    @social = @profile.socials.find_or_create_from_auth_hash(auth_hash)
    if auth_hash.provider == "google_oauth2"
      flash[:success] = "Your faskyn calendar is now connected to your google calendar!"
    else  
      flash[:success] = "#{@social.provider.camelize} account was successfully updated!"
    end
  rescue
    flash[:warning] = "There was an error while trying to authenticate you!"
  end
  redirect_to edit_user_profile_path(current_user)
end

private

def auth_hash
  request.env['omniauth.auth']
end
社交网站

def self.find_or_create_from_auth_hash(auth_hash)
  calendar not to update the profile
  social_acc = where(provider: auth_hash.provider).first_or_create
  if auth_hash.provider == "google_oauth2"
  social_acc.update(
    uid: auth_hash.uid,
    email: auth_hash.info.email,
    token: auth_hash.credentials.token,
    refresh_token: auth_hash.credentials.refresh_token,
    expires_at: Time.at(auth_hash.credentials.expires_at).to_datetime)
  social_acc
else
  social_acc.update(
    #no first_name, last_name and phone for twitter
    uid: auth_hash.uid,
    token: auth_hash.credentials.token,
    secret: auth_hash.credentials.secret,
    picture_url: auth_hash.info.image,
    location: auth_hash.info.location,
    description: auth_hash.info.description,
    first_name: auth_hash.info.first_name || nil,
    last_name: auth_hash.info.last_name || nil,
    phone: auth_hash.info.phone || nil,
    page_url:   case social_acc.provider
                when 'twitter' then auth_hash.info.urls.Twitter
                when 'linkedin' then auth_hash.info.urls.public_profile
                end
    )
  social_acc
end

你在
auth\u info
中得到了什么?我刚刚检查了它,它没有给我任何东西检查你的请求。env,我打赌它没有omniauth.auth密钥?你在
auth\u info
中得到了什么?我刚刚检查了它,它没有给我任何东西检查你的请求。env,我打赌它里面没有omniauth.auth密钥?我需要yahoo。我已经使用google进行了身份验证…基本上我的auth_info变量中没有任何内容。即使现在我也在使用实例变量添加:raise:测试你的索引操作,并在控制台中查看auth_哈希显示的内容。或者你已经检查过响应了吗?实际上我不明白你想说什么我没有在rails中进行测试。你能告诉我在控制台上做什么吗?这段视频在8:30你应该看到auth_hash属性。如果你调用一个不存在的,那么你将得到零。假设您键入了auth_info[:credentials][:token],但它应该是auth_info[:credentials][:access_token],所以你得到零。我需要雅虎..我已经用谷歌做了身份验证…基本上我在我的auth_info变量中没有得到任何东西。即使现在我在那里使用实例变量add:raise:test到你的索引操作,并在控制台中查看auth_hash显示的内容。或者你已经检查过响应了吗?实际上我不明白你想说什么我没有在rails中进行测试。你能告诉我在控制台上做什么吗?这段视频在8:30你应该看到auth_hash属性。如果你调用一个不存在的,那么你将得到零。假设您键入了auth_info[:credentials][:token],但它应该是auth_info[:credentials][:access_token],所以您得到的是零。
def self.find_or_create_from_auth_hash(auth_hash)
  calendar not to update the profile
  social_acc = where(provider: auth_hash.provider).first_or_create
  if auth_hash.provider == "google_oauth2"
  social_acc.update(
    uid: auth_hash.uid,
    email: auth_hash.info.email,
    token: auth_hash.credentials.token,
    refresh_token: auth_hash.credentials.refresh_token,
    expires_at: Time.at(auth_hash.credentials.expires_at).to_datetime)
  social_acc
else
  social_acc.update(
    #no first_name, last_name and phone for twitter
    uid: auth_hash.uid,
    token: auth_hash.credentials.token,
    secret: auth_hash.credentials.secret,
    picture_url: auth_hash.info.image,
    location: auth_hash.info.location,
    description: auth_hash.info.description,
    first_name: auth_hash.info.first_name || nil,
    last_name: auth_hash.info.last_name || nil,
    phone: auth_hash.info.phone || nil,
    page_url:   case social_acc.provider
                when 'twitter' then auth_hash.info.urls.Twitter
                when 'linkedin' then auth_hash.info.urls.public_profile
                end
    )
  social_acc
end