用Devise登录后出现奇怪的重定向 [英] Weird redirect after login with Devise

查看:89
本文介绍了用Devise登录后出现奇怪的重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用Devise的这个应用程序,登录后,用户被重定向到一个空白页面,路径为 /users/sign_in.user



为什么Devise重定向到此路径?这是我得到的日志条目:

 在2011-11-开始POST/users/sign_in.user为127.0.0.1参数:{utf8=>✓,authenticity_token=>ukqyLFgApCSybuIlVynPwj / xgdI / WuHLxoFxOsY4wgQ =,user=> {email=>felipe.coury@gmail.com,password=>[FILTERED],remember_me=>0},提交=>Entrar} 
用户加载(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
完成406在112ms不可接受

这是我的完整的 routes.rb 文件:

  MyApp :: Application.routes.draw 
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)

资源:cursos
资源:matriculas
资源:modulo_statuses
end

我尝试使用 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

但日志条目甚至不会显示。



有没有人有什么想法这个事情发生了吗?

解决方案

这可能是因为这样的东西被调用: user_session_path(user) ,实际上不需要用户作为参数,所以Rails将其视为格式。在您的登录视图中,这可能是错误的 form_for 调用。 after_sign_in_path_for 没有被调用,因为Rails没有考虑给定的URL一个有效的请求(这就是为什么响应是406可以接受的)。


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.

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

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

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?

解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆