I have this code that create a link to a page to login to facebook at 'auth/facebook'
index.html.haml
- if current_user
= link_to "Sign out", signout_path, id: "sign_out"
- else
= link_to "Sign in with Facebook", "/auth/facebook", id: "sign_in"
But if i want if current_user to redirect to '/dashboard' so that when someone is logged in they get redirected from the login page automatically.
sessions controller
class SessionsController < ApplicationController
def create
user = User.from_omniauth(env["omniauth.auth"])
session[:user_id] = user.id
redirect_to dashboard_url
end
def destroy
session[:user_id] = nil
redirect_to login_url
end
end
在SessionsController
,只需检查会话并重定向它是否已经存在,除了尝试注销的情况除外:
before_filter :except => [:destroy] {|c| c.redirect_to dashboard_path if c.current_user }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.