简体   繁体   English

Rails设计,没有路线匹配注销

[英]rails devise, no route matches logout

Though there're lots of similar questions, i've searched for it for hours but still can not fix it. 尽管有很多类似的问题,但我已经搜索了几个小时,但仍无法解决。

Env rails 3.0.9 ruby 1.9.2 devise 1.4.2 环保滑轨3.0.9红宝石1.9.2设计1.4.2

I changed the default login url using: 我使用以下命令更改了默认登录网址:

 5   resources :users
 6   devise_for :users, :path => "", :path_names => { :sign_in => 'login', :sign_out  
     => 'logout', :password => 'secret', :confirmation => 'verification', :unlock =>
     'unblock', :registration => 'register', :sign_up => 'cmon_let_me_in' }

And the http://localhost:3000/login works fine for me But I include http:// localhost:3000 / login对我来说很好,但我包括

 = link_to 'sign_out', destroy_user_session_path, :method => :delete

in my application.haml, after i click it, it says that no route matchs "/logout" Why? 在我的application.haml中,单击它后,它说没有路由匹配“ / logout”,为什么? Please help me. 请帮我。

I had a nearly identical problem and thanks to SO fixed it quite easily ( link to my question ). 我有一个几乎相同的问题,并且由于使用SO非常容易地解决了它( 链接到我的问题 )。 First, make sure you have <%= javascript_include_tag :defaults %> in your layout file "application.html.erb." 首先,请确保您的布局文件“ application.html.erb”中具有<%= javascript_include_tag :defaults %>

Then, in your config -> initializers -> "devise.rb" file make sure it says: 然后,在您的配置->初始化程序->“ devise.rb”文件中,确保其显示为:

config.sign_out_via = :delete

and your "sign_out" code destroy_user_session_path, :method => :delete should work. 并且您的“ sign_out”代码destroy_user_session_path, :method => :delete应该可以工作。

A little late to this party, but here's some help from another answer 这次聚会有点晚了,但这是另一个答案的帮助

Specify your method: 指定您的方法:

<%= link_to "sign out", destroy_user_session_path, method: :delete %>

config/initializers/devise.rb设置config.sign_out_via = :get ,以将以下代码用于您的注销链接。

<%= link_to "Sign Out", destroy_user_session_path %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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