2

我安装了设计,它工作正常,但登录重定向。当用户从应用程序的任何页面登录时,Devise 会将用户重定向到主页,而不是在同一页面上重定向。我尝试实施设计的 How_to 解决方案,但没有帮助。

我在 application_controller 中写道:

def after_sign_in_path_for(resource)
 current_user_path 
end

但它给出了错误:

undefined local variable or method `current_user_path' for #<Devise::SessionsController:0xaeacc34>

当我写:

def after_sign_in_path_for(resource)
 current_user_path 
end

它给 :

undefined method `user_url'

这个问题的解决方案是什么?任何机构都可以在这方面提供帮助吗?

4

2 回答 2

1

您需要重定向到哪个场景(错误或成功)的其他地方?通常在用户成功登录后使用 after_sign_in_path_for。所以:

如果您没有覆盖设计默认功能,则使用下面的代码将控件导航到特定的自定义页面。current_user在此操作中也可以访问。

def after_sign_in_path_for(resource)
    scope = Devise::Mapping.find_scope!(resource)
    scope_path = :"#{scope}_root_path"
    respond_to?(scope_path, true) ? send(scope_path) : root_url
end

更新:另一个例子如下:

 def after_sign_in_path_for(resource_or_scope)
    current_user.admin? ? dashboard_admin_home_index_path : current_user.sign_in_count >= 1 ? "/home/dashboard" : "/#{current_user.role}/dashboard"
  end
于 2013-03-28T08:38:34.613 回答
1

您可以使用 request.referer

def after_sign_in_path_for(resource_or_scope)
  request.referer
end
于 2013-04-25T09:15:13.873 回答