request.referrer
这只有在指向某些尝试进行另一次登录的操作时才有意义。
您可以通过始终打开终端窗口运行来了解这一点tail -f log/development.log
。您需要的所有信息都应该在那里。请求来自哪里,它重定向到哪里,为什么还有另一个重定向。
无论如何,还有其他方法可以将用户送回其原点。request.referrer
是一个可选的标头,通常在测试中会带来麻烦。设计本身提供了定制after_sign_in_path_for
方法的不同方式。
阅读方法文档:
# The default url to be used after signing in. This is used by all Devise
# controllers and you can overwrite it in your ApplicationController to
# provide a custom hook for a custom resource.
#
# By default, it first tries to find a valid resource_return_to key in the
# session, then it fallbacks to resource_root_path, otherwise it uses the
# root path. For a user scope, you can define the default url in
# the following way:
#
# map.user_root '/users', :controller => 'users' # creates user_root_path
#
# map.namespace :user do |user|
# user.root :controller => 'users' # creates user_root_path
# end
#
# If the resource root path is not defined, root_path is used. However,
# if this default is not enough, you can customize it, for example:
#
# def after_sign_in_path_for(resource)
# stored_location_for(resource) ||
# if resource.is_a?(User) && resource.can_publish?
# publisher_url
# else
# signed_in_root_path(resource)
# end
# end
#
def after_sign_in_path_for(resource_or_scope)
stored_location_for(resource_or_scope) || signed_in_root_path(resource_or_scope)
end