【发布时间】:2011-04-03 18:56:30
【问题描述】:
我的 Omniauth 回调中有以下内容:
@user = User.find_for_linked_in_oauth(env["omniauth.auth"], current_user)
我希望任何一种方式都能获得用户对象。她是用户方法。现在,我正在测试它无法找到现有用户的情况,因为它尚未创建:
def self.find_for_linked_in_oauth(omniauth_hash, signed_in_resource=nil)
debugger
#omniauth_hash is a hash passed in from env["omniauth_hash"] by callback controller
linkedin_uid = omniauth_hash['uid']
debugger
if user = User.find_by_linkedin_uid(linkedin_uid)
debugger
user
else # Create an user with a stub password.
#redirect to a page to ask for an email address and display information
#User.create!(:email => "token@email.com", :linkedin_uid => linkedin_uid, :password => Devise.friendly_token[0,20])
user = User.new
user.first_name = omniauth_hash['user_info']['first_name']
user.last_name = omniauth_hash['user_info']['last_name']
user.linkedin_uid = linkedin_uid
user
debugger
end
目前,使用调试器,我返回 '1' 作为 p @user 的值。
我希望将新创建的用户对象传回,这样我就可以要求当前用户在保存之前添加其他信息。
为什么我没有将新创建的用户作为@user 的值?
【问题讨论】:
-
调试器变量/方法有什么用?这就是 ruby 在 else 块中返回的内容,无论调试器的值是什么。将
user放在下面而不是上面,它将返回用户。 -
@scragz -- 我认为你是对的 -- 现在我收到一个 multi_json 错误,所以无法测试它......有什么想法吗? :)
标签: ruby-on-rails ruby callback debugging models