需要重定向在主页如果用户已经登录

时间:2014-11-27 06:25:12

标签: php ruby-on-rails ruby-on-rails-3 devise

我正在omniauth使用devise。我的控制器在下面

 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

如果用户已登录并持续,则将用户重定向到注册页面。我做了哪些更改以在主页重定向用户....... ????? 请帮帮我

1 个答案:

答案 0 :(得分:0)

在sign_in路径后设置了吗?

#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 devise with omniauth

Code Example

如果您遇到其他错误,请在此处粘贴