使用 Devise 登录后的奇怪重定向 [英] Weird redirect after login with Devise
问题描述
我有一个使用 Devise 的应用程序,登录后用户被重定向到一个空白页面,路径为 /users/sign_in.user
.
I have this application where I use Devise and, after login the user is redirected to a blank page with the path /users/sign_in.user
.
为什么 Devise 重定向到这个路径?这是我得到的日志条目:
Why is Devise redirecting to this path? Here's the log entry I get:
Started POST "/users/sign_in.user" for 127.0.0.1 at 2011-11-10 15:56:03 -0200
Processing by Users::SessionsController#create as
Parameters: {"utf8"=>"✓", "authenticity_token"=>"ukqyLFgApCSybuIlVynPwj/xgdI/WuHLxoFxOsY4wgQ=", "user"=>{"email"=>"felipe.coury@gmail.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Entrar"}
User Load (1.8ms) SELECT `users`.* FROM `users` WHERE `users`.`email` = 'felipe.coury@gmail.com' LIMIT 1
(0.2ms) BEGIN
(1.0ms) UPDATE `users` SET `last_sign_in_at` = '2011-11-09 18:47:04', `current_sign_in_at` = '2011-11-10 17:56:04', `sign_in_count` = 14, `updated_at` = '2011-11-10 17:56:04' WHERE `users`.`id` = 1
(0.3ms) COMMIT
Completed 406 Not Acceptable in 112ms
这是我完整的 routes.rb
文件:
Here's my complete routes.rb
file:
MyApp::Application.routes.draw do
root :to => "site#home"
match 'biblioteca' => 'site#library', :as => :library
devise_for :users, :controllers => { :sessions => "users/sessions" }
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
resources :cursos
resources :matriculas
resources :modulo_statuses
end
我尝试在 ApplicationController
中使用 after_sign_in_path_for
:
I tried using after_sign_in_path_for
in ApplicationController
:
def after_sign_in_path_for(resource_or_scope)
Rails.logger.info "***** LOGGED IN, GOING TO #{root_path}"
root_path
end
但日志条目甚至没有出现.
But the log entry doesn't even appear.
有人知道为什么会这样吗?
Does anyone have any idea why this happens?
推荐答案
这可能是因为正在调用这样的东西:user_session_path(user)
而你实际上并不需要用户作为参数,因此 Rails 将其视为格式.这在您的登录视图中的 form_for
调用中可能是错误的.after_sign_in_path_for
没有被调用,因为 Rails 没有将给定的 URL 视为有效请求(这就是响应 406 可接受的原因).
This is probably happening because something like this is being called: user_session_path(user)
and you actually don't need the user as argument, so Rails treats it as the format. This is likely wrong in the form_for
call in your sign in view. after_sign_in_path_for
is not being called because Rails is not considering the given URL a valid request (that's why the response is 406 acceptable).
这篇关于使用 Devise 登录后的奇怪重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!