簡體   English   中英

登錄管理員后將設計重定向到頁面

[英]Devise Redirect to Page After Sign In Admin

我在Rails 4上。

我進行了設置,因此當用戶注冊或登錄(設計)時,它將重定向到他們上次訪問的頁面。 它工作得很好。

但是,我很難弄清楚如何完全忽略管理員。 當以管理員身份登錄時(管理員是自己的模型),我收到一個重定向循環,因為它想同時返回上一頁和管理面板。

這是我的application_controller:

after_filter :store_location

  def store_location
    # store last url as long as it isn't a /users path
    session[:previous_url] = request.fullpath unless request.fullpath =~ /\/users/ 
  end

  def after_sign_in_path_for(resource)
    session[:previous_url] || root_path
  end

如果它是管理員登錄,則忽略after_sign_in_path_for的最佳方法是什么?

因為我們在application_controller中創建了這樣的方法,所以我們需要在路線上或其他路線上供應。 一種簡單的解決方案是下面的解決方案。

def after_sign_in_path_for(resource)
  if resource.admin? #Assuming there is such a function
    root_path
  else
    session[:previous_url] || root_path
  end
end

暫無
暫無

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

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