Ruby on rails 3 如何在AccessDenied异常后注销用户?(设计)

Ruby on rails 3 如何在AccessDenied异常后注销用户?(设计),ruby-on-rails-3,devise,Ruby On Rails 3,Devise,我的应用程序控制器中有: rescue_from CanCan::AccessDenied do |exception| redirect_to destroy_user_session_path, :method => :delete, :alert => exception.message end 我想在用户试图打开无法访问的资源时注销该用户。 但是,我知道,没有使用“删除”方法 No route matches [GET] "/authenticate/users/sig

我的应用程序控制器中有:

rescue_from CanCan::AccessDenied do |exception|
  redirect_to destroy_user_session_path, :method => :delete, :alert => exception.message
end
我想在用户试图打开无法访问的资源时注销该用户。 但是,我知道,没有使用“删除”方法

No route matches [GET] "/authenticate/users/sign_out"
如何注销用户并显示登录表单(新建用户会话)

顺便说一句,正常的注销链接工作得很好

<%= link_to "Logout: #{current_user.name}", destroy_user_session_path, :method => :delete %>
:删除%>
Ace怎么样

rescue_from CanCan::AccessDenied do |exception|
  sign_out :user if user_signed_in?
  redirect_to new_user_session_path, alert: exception.message
end

但我觉得这不是一个可以期待的行为。

太好了,这很有效!我明白你的意思,但至少我现在知道怎么做了。首先注销用户,然后去你想去的任何地方,对吧!?谢谢!