2017-06-22 61 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

相关问题