简体   繁体   中英

Getting 406 after Devise sign_out

I am using devise (3.1.0.rc2), rails 3.2.6, unicorn and have added

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

to my application.rb and am still getting a 406 error when attempting to redirect after logout in my application controller.This is my call

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

Here is the application controller:

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

Logfile:

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)

What am I missing?

It assumed current_user.id as the format.

I was calling

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

instead of

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

destroy_user_session_path(current_user) still works, but it assumes the current_user id as the format.

Credit goes to https://stackoverflow.com/users/588267/jose-valim on github: https://github.com/plataformatec/devise/issues/2209#issuecomment-23605974

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM