Rails&设计:destroy_user_session_path转到用户#显示?

时间:2015-11-30 17:47:04

标签: ruby-on-rails devise

漂亮的标准链接:

<li><%= link_to 'Log Out', destroy_user_session_path(current_user) %></li>

rake routes:

destroy_user_session DELETE   /users/sign_out(.:format)                 devise/sessions#destroy

routes.rb中:

  devise_for :users, :controllers => { omniauth_callbacks: "users/omniauth_callbacks", sessions: "users/sessions" }

用户/ sessions_controller.rb:

类Users :: SessionsController&lt;设计:: SessionsController

  def destroy
    binding.pry
    cookies.delete(:auth_token)
    flash[:notice] = "Successfully Logged Out"
    redirect_to new_session_path
  end

end

binding.pry甚至没有被调用。该链接将我带到网址/users/sign_out,但视图是用户#show。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

destroy动作需要DELETE HTTP动词,如rake routes输出中所示。

您需要将method: :delete添加到链接帮助程序的末尾,否则链接将生成GET请求。