【问题标题】:unable to switch back user using switch user gem rails无法使用切换用户 gem rails 切换回用户
【发布时间】:2013-10-22 17:31:25
【问题描述】:

我正在使用switch_user gem 这个question 几乎与我遇到的问题完全相同。我已经尝试了与问题相同的方法,就像readme 所说的那样。这是我尝试过的代码。

 config.controller_guard = { |current_user, request, original_user|
  current_user && current_user.has_role? :admin || original_user}

  # view_guard is a block,
  # if it returns true, the switch user select box will be shown,
  # else the select box will not be shown
  # if you switch from admin to "user", the current_user param is "user"
config.view_guard = { |current_user, request, original_user|
  current_user && current_user.has_role? :admin || original_user}
  # redirect_path is a block, it returns which page will be redirected
  # after switching a user.

#  if lambda{|current_user| current_user.admin?}
#   config.redirect_path = lambda{|request,params| "/admin_dashboard"}
# elsif lambda{|current_user| current_user.performer?}
#   config.redirected_path = lambda{|request,params| "/"}
# elsif lambda{|current_user| current_user.white_label?}
#   config.redirected_path = lambda{|request,params| "/white_label_dashboard"}
# else
#   config.redirected_path = lambda{|request,params| "/customer_dashboard"}
# end
  # helper_with_guest is a boolean value, if it set to false
  # the guest item in the helper won't be shown
  config.helper_with_guest = false

  # false = login from one scope to another and you are logged in only in both scopes
  # true = you are logged only into one scope at a time
  config.login_exclusive = true

  # switch_back allows you to switch back to a previously selected user. See
  # README for more details.
config.switch_back = true

我仍然无法切换回来。我如何找到是否设置了原始用户?

【问题讨论】:

    标签: ruby-on-rails switch-user


    【解决方案1】:

    如果有人还在为switch_user gem 苦苦挣扎,我强烈推荐Pretender by Ankane。我只用了 10 分钟就安装好了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多