我尝试使用omniauth从Facebook返回的uid更新我的Devise模型Vendor
。这不是登录或注册我的应用程序,而是与Facebook集成,如果这是有道理的。我试图使用这种模式:
class Vendors::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
@vendor = current_vendor
uid = request.env["omniauth.auth"]["uid"]
puts uid
@vendor.update_attributes(:uid => uid)
redirect_to vendors_dashboard_path
end
end
当此方法尝试更新属性时,我一直收到302 Found。当我puts uid
时,我看到正确的uid被返回,但是params哈希由state
和code
属性组成。我对这种回调方法有什么不了解?
服务器日志:
Processing by Vendors::OmniauthCallbacksController#facebook as HTML
Parameters: {"code"=>"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "state"=>"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
Vendor Load (0.4ms) SELECT "vendors".* FROM "vendors" WHERE "vendors"."id" = 25 LIMIT 1
(0.2ms) BEGIN
(0.2ms) COMMIT
Redirected to http://localhost:3000/vendors/dashboard
Completed 302 Found in 152ms (ActiveRecord: 2.9ms)
答案 0 :(得分:0)
您被内置的批量分配保护阻止,尝试仅使用update_column更新列,看看是否能解决您的问题。由于AR与它的模型基本相同,因此提交不会将任何内容写回数据库。
尝试以下方法:
class Vendors::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
@vendor = current_vendor
uid = request.env["omniauth.auth"]["uid"]
puts uid
@vendor.update_column(:uid, uid)
redirect_to vendors_dashboard_path
end
end