Rails 设计,没有路线匹配注销
尽管有很多类似的问题,但我已经搜索了几个小时但仍然无法解决它。
环境 导轨3.0.9 红宝石 1.9.2 devise 1.4.2
我使用以下方法更改了默认登录网址:
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' }
http://localhost:3000/login 对我来说效果很好 但我包含
= link_to 'sign_out', destroy_user_session_path, :method => :delete
在我的application.haml中,点击它后,它说没有路由匹配“/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
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
= 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?
Please help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了几乎相同的问题,并且非常容易修复它(链接到我的问题)。首先,确保布局文件“application.html.erb”中有
<%= javascript_include_tag :defaults %>
。然后,在你的配置中 ->初始化器 -> “devise.rb”文件确保其内容为:
config.sign_out_via = :delete
和您的“sign_out”代码
destroy_user_session_path, :method =>; :delete
应该可以。I had a nearly identical problem and thanks to SO fixed it quite easily (link to my question). First, make sure you have
<%= javascript_include_tag :defaults %>
in your layout file "application.html.erb."Then, in your config -> initializers -> "devise.rb" file make sure it says:
config.sign_out_via = :delete
and your "sign_out" code
destroy_user_session_path, :method => :delete
should work.这次聚会有点晚了,但这里有另一个答案
指定您的方法:
A little late to this party, but here's some help from another answer
Specify your method:
在 config/initializers/devise.rb 中设置 config.sign_out_via = :get 以使用以下代码作为注销链接。
Set
config.sign_out_via = :get
inconfig/initializers/devise.rb
to use the following code for your sign out link.