2017-06-22 106 views
0

我使用omniauth-facebook gemDevise成功實施了Facebook身份驗證。然而,我想要做的是,在Facebook認證之後,將它們重定向到一個可以在創建記錄之前指定密碼(和密碼確認)的表單。Rails - 在Facebook Omniauth註冊期間獲得其他字段

我該怎麼做?

我的代碼是基於創業板的文檔上非常標準:

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController 

    def facebook 
    @user = User.from_omniauth(request.env["omniauth.auth"]) 

    if @user.persisted? 
     sign_in_and_redirect @user, :event => :authentication 
     set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format? 
    else 
     session["devise.facebook_data"] = request.env["omniauth.auth"] 
     redirect_to new_user_registration_url 
    end 
end 

    def failure 
    redirect_to root_path 
    end 
end 

user.rb

def self.from_omniauth(auth) 
    where(provider: auth.provider, uid: auth.uid).first_or_create do |user| 
    user.email = auth.info.email 
    user.username = auth.info.name.downcase.gsub(" ", "")  
    end 
end 
+0

好,這是omniauth的整個目的,用戶不必記住password..just好奇,爲什麼你想呢? –

+0

爲true。其實,我也想要其他領域。如他們的國家。 – yellowreign

回答

0

如果我理解正確的,你需要的用戶之前填寫一份profile頁導航通過應用程序..類似下面的東西應該有所幫助..

在您的application_controller.rb,

def after_sign_in_path_for(resource) 
    resource.profile_complete? ? root_path : user_profile_path(resource) 
end 

Devise Wiki

相關問題