我正在尝试在Rails 5应用程序中注销Devise时获取JSON响应消息。
class SessionsController < Devise::SessionsController
around_action :after_logout_message
protected
def after_logout_message
set_flash_message! :notice, :signed_out
yield
end
private
def respond_to_on_destroy
# We actually need to hardcode this as Rails default responder doesn't
# support returning empty response on GET request
respond_to do |format|
format.json { render json: flash }
format.any(*navigational_formats) { redirect_to after_sign_out_path_for(resource_name) }
end
end
end
和我的路线文件
get 'login', to: 'sessions#new', as: :new_user_session
post 'login', to: 'sessions#create', as: :user_session
match 'logout', to: 'sessions#destroy', as: :destroy_user_session, via: Devise.mappings[:user].sign_out_via
为什么这不起作用?其他所有行动似乎都很好。