Rails 3 和 Devise - 将应用程序转换为 Rails 3 后退出无法正常工作

发布于 2024-12-12 09:42:51 字数 691 浏览 1 评论 0原文

我的路线

devise_for :users
devise_for :admin_users, ActiveAdmin::Devise.config #I have also tried removing this for any conflicts
resources :users

退出链接。路由到 /users/sign_out 就好了

<%= link_to "Logout", destroy_user_session_path, :method => :delete %>

尝试注销,出现错误:

Couldn't find User with id=sign_out

如果我然后删除资源:users,我得到:出了

The action 'sign_out' could not be found for UsersController

什么问题?完全相同的代码适用于Rails 2.3.8和相应的Devise版本

登录等工作正常。

我的设置是:

  • Ruby 1.9.2
  • Rails 3.1.1.rc3
  • Devise 1.4.8

My routes

devise_for :users
devise_for :admin_users, ActiveAdmin::Devise.config #I have also tried removing this for any conflicts
resources :users

The sign out link. Routes to /users/sign_out just fine

<%= link_to "Logout", destroy_user_session_path, :method => :delete %>

Trying to sign out, gives me the error:

Couldn't find User with id=sign_out

If I then remove the resource :users, I get:

The action 'sign_out' could not be found for UsersController

What's wrong? The exact same code worked with Rails 2.3.8 and the corresponding Devise version

Logging in etc. works fine.

My setup is:

  • Ruby 1.9.2
  • Rails 3.1.1.rc3
  • Devise 1.4.8

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

煮茶煮酒煮时光 2024-12-19 09:42:51

首先,对 UsersController 和 Devise 使用相同的路径并不是一个好主意。我建议为 Devise 使用像“/accounts”这样的路径。

但这可能不是导致注销问题的原因,因为在routes.rb中,devise_for :users位于resources:users之前。原因似乎是,除非问题中有拼写错误,否则 destroy_user_session_path 之后没有逗号。 <代码>:方法=> :delete 将被解释为 destroy_user_session_path 的参数,除非有逗号。

另外,请确保在 application.js 中包含 jquery 和 jquery_ujs,因为 :method => 需要它们。 :delete 即可工作。

First of all, using the same path for UsersController and Devise isn't a great idea. I would suggest using a path like '/accounts' for Devise.

But this probably isn't the cause of your sign out problem, as devise_for :users comes before resources :users in routes.rb. What seems to be the cause is, unless there'a typo in the question, that there's no comma after destroy_user_session_path. :method => :delete will be interpreted as a parameter to destroy_user_session_path unless there's a comma.

Also, make sure you're including jquery and jquery_ujs in application.js, as these are required for :method => :delete to work.

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