簡體   English   中英

是否可以在HAML / Rails中重定向頁面?

[英]Is it possible to redirect a page in HAML/Rails?

我有這段代碼可創建指向頁面的鏈接,以在“ auth / facebook”登錄到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"

但是,如果我想讓current_user重定向到'/ dashboard',以便當某人登錄時,他們會自動從登錄頁面重定向。

會話控制器

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 }

暫無
暫無

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

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