简体   繁体   English

登录管理员后将设计重定向到页面

[英]Devise Redirect to Page After Sign In Admin

I am on Rails 4. 我在Rails 4上。

I have it setup so when a user signs up or logs in (devise) it will redirect to the page they were last on. 我进行了设置,因此当用户注册或登录(设计)时,它将重定向到他们上次访问的页面。 It works very nicely. 它工作得很好。

However, I am having trouble figuring out how to ignore the admin completely. 但是,我很难弄清楚如何完全忽略管理员。 When signing in as an admin (admin is its own model), I receive a redirect loop, as it wants to go back to the previous page and the admin panel at the same time. 当以管理员身份登录时(管理员是自己的模型),我收到一个重定向循环,因为它想同时返回上一页和管理面板。

Here is my application_controller: 这是我的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

What would be the best way to ignore the after_sign_in_path_for if it is an admin signing in? 如果它是管理员登录,则忽略after_sign_in_path_for的最佳方法是什么?

We need to supply on route or another since we creating such a method in our application_controller. 因为我们在application_controller中创建了这样的方法,所以我们需要在路线上或其他路线上供应。 The simple solution would be the one below. 一种简单的解决方案是下面的解决方案。

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