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

发布于 2024-11-25 19:28:15 字数 682 浏览 1 评论 0原文

尽管有很多类似的问题,但我已经搜索了几个小时但仍然无法解决它。

环境 导轨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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

绝影如岚 2024-12-02 19:28:15

我遇到了几乎相同的问题,并且非常容易修复它(链接到我的问题)。首先,确保布局文件“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.

不羁少年 2024-12-02 19:28:15

这次聚会有点晚了,但这里有另一个答案

指定您的方法:

<%= link_to "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 %>
迷路的信 2024-12-02 19:28:15

在 config/initializers/devise.rb 中设置 config.sign_out_via = :get 以使用以下代码作为注销链接。

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

Set config.sign_out_via = :get in config/initializers/devise.rb to use the following code for your sign out link.

<%= link_to "Sign Out", destroy_user_session_path %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文