Rails 3 和 Devise - 将应用程序转换为 Rails 3 后退出无法正常工作
我的路线
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,对 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 beforeresources :users
in routes.rb. What seems to be the cause is, unless there'a typo in the question, that there's no comma afterdestroy_user_session_path
.:method => :delete
will be interpreted as a parameter todestroy_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.