0

我正在使用设计(3.1.0.rc2),rails 3.2.6,独角兽并添加了

config.to_prepare do
 DeviseController.respond_to :html, :json
end

到我的 application.rb 并且在我的应用程序控制器中注销后尝试重定向时仍然收到 406 错误。这是我的电话

<%= link_to 'Logout' , destroy_user_session_path(current_user), confirm: 'Are you sure?', method:'delete' %>

这是应用程序控制器:

class ApplicationController < ActionController::Base

respond_to :json, :html

def after_sign_out_path_for(resource_or_scope)
    Rails.logger.info("logout")
    redirect_to "/"
end

protect_from_forgery
end

日志文件:

Started DELETE "/users/sign_out.4" for 127.0.0.1 at 2013-08-31 08:48:55 -0400
Processing by Devise::SessionsController#destroy as 
Parameters: {"authenticity_token"=>"k2rUBfhoI964j5SQ4Cce9irDxjacFsX614L/XhUtAXM="}
logout
Redirected to http://localhost:4000/
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = 4 LIMIT 1
(0.2ms) BEGIN
(0.2ms) COMMIT
Completed 406 Not Acceptable in 8ms (ActiveRecord: 1.0ms)

我错过了什么?

4

1 回答 1

0

它假定 current_user.id 作为格式。

我在打电话

<%= link_to 'Logout' , destroy_user_session_path(current_user), confirm: 'Are you sure?', method:'delete' %>

代替

<%= link_to 'Logout' , destroy_user_session_path, confirm: 'Are you sure?', method:'delete' %>

destroy_user_session_path(current_user) 仍然有效,但它假定 current_user id 作为格式。

归功于 github上https://stackoverflow.com/users/588267/jose-valim:https://github.com/plataformatec/devise/issues/2209#issuecomment-23605974

于 2013-08-31T13:31:57.483 回答