繁体   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