我是红宝石环境的新手。
在我的 ruby 应用程序中,我正在使用omniauth 对用户进行身份验证,并且我能够为登录用户保存facebook 令牌,问题是我想将此令牌信息作为参数传递给位于其他控制器中的考拉?
怎么做?请帮忙。
我的 OMNIAUTH 控制器:
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
@user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)
...
end
用户.rb
def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
data = access_token.extra.raw_info
token = access_token.credentials.token //i want to pass this to invite controller
cookies[:myKey] = token
if user = self.where(:email => data.email).first
if(!user.facebook_id)
if(user.sign_in_count != 0)
user.facebook_id = data.id
user.token = access_token
user.save
else
user.destroy
user = User.new(:name=>(data.name).split(" ")[0], :email => data.email, :password => Devise.friendly_token[0,20], :provider => "facebook", :facebook_id => data.id)
user.skip_confirmation!
user.save!
end
end
user
else # Create a user with a stub password.
user = User.new(:name=>(data.name).split(" ")[0], :email => data.email, :password => Devise.friendly_token[0,20], :provider => "facebook", :facebook_id => data.id)
user.skip_confirmation!
user.save!
user
end
end
我的邀请控制器 (我正在尝试使用 koala gem 获取 facebook 用户数据)
class InviteController < ApplicationController
def invite
fb ||= Koala::Facebook::API.new(cookies[:myKey])
@friends = fb.get_connections("me", "friends")
render json: @friends
end
end