Rails Omniauth Facebook登录重定向到注册

时间:2014-05-23 22:58:09

标签: ruby-on-rails facebook omniauth

出于某种原因,我的Omniauth Facebook登录重定向到/ users / sign_up# = - 但是看起来似乎正常。我在routes.rb中有这个:

devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }

我在application.html.erb中有这个:

 <%= link_to "", user_omniauth_authorize_path(:facebook, :origin=>"root_url") %> 
                      <%= link_to(image_tag("FB-Login.png"),    
 user_omniauth_authorize_path(:facebook), :origin=>"root_url", class:"mycss") %>

我在application_controller.rb中有这个:

def after_sign_in_path_for(resource_or_scope)
      Rails.logger.level = 0 
      logger.debug "after_sign_in_path_for"
          logger.debug "Session: #{@session.inspect}"
      logger.debug "omniauth.origin: #{omniauth.origin}"
          logger.debug "root_url: #{root_url}"
    ##  if request.env['omniauth.origin']
##    request.env['omniauth.origin']
      request.env['omniauth.origin'] || root_url
  end

有趣的是日志语句没有显示在heroku日志中 - 看起来像是没有调用after_sign_in_path_for ??

任何帮助表示赞赏, 斯拉夫科

1 个答案:

答案 0 :(得分:2)

也许该用户已经存在?

尝试在持久性之前检查用户是否存在:

def facebook
  @user = User.from_omniauth(request.env["omniauth.auth"])
  if @user
    sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
    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