簡體   English   中英

如果用戶已經登錄,則需要在主頁上重定向

[英]Need To redirect At home page If user Already logged in

我使用omniauthdevise 我的控制器在下面

 class OmniauthCallbacksController < Devise::OmniauthCallbacksController
      def facebook
        # You need to implement the method below in your model (e.g. app/models/user.rb)
        @user = User.from_omniauth(request.env["omniauth.auth"])



        if @user.persisted?
          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
    end

如果用戶已經登錄並堅持下去,這會將用戶重定向到注冊頁面。我要進行哪些更改以將用戶重定向到首頁......... ?????? 請幫幫我

登錄后路徑設置了嗎?

#application_controller.rb
def after_sign_in_path_for(resource_or_scope)
  case resource_or_scope
  when :user, User

    root_path
  else
    super
  end
end

Rails用omniauth設計的示例

代碼示例

如果您遇到其他錯誤,請粘貼在這里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM