破坏设备注册的途径是什么? [英] what's the path to destroy registration with devise

查看:135
本文介绍了破坏设备注册的途径是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加一个链接,以便用户可以摧毁他/她自己的帐户。我正在使用内置的注册类。

I'm trying to add a link so the user can destroy his/her own account. I'm using the built-in registration class.

在我看来,我有<%= link_to'Destroy',current_user,confirm => 你确定要破坏你的账号吗?,method => :删除%> 指向本地主机:3000 / users / 4通过示例

In my view I have <%= link_to 'Destroy', current_user, :confirm => 'Are you sure you want to destroy your account?', :method => :delete %> pointing to localhost:3000/users/4 by example

首先,是正确的链接使用?
其次,如何重定向到根路径,因为目前它看起来像是尝试重定向到具有id 4的用户(并且它由于受保护而失败)。

First of all, is that the correct link to use? Secondly, how to redirect to root path because presently it looks like it tries to redirect to user with id 4 (and it fails because it is protected).

Rake路线给出 DELETE /users(.:format){:action =>destroy,:controller =>devise / registrations}

提前感谢。

推荐答案

尝试

<%= link_to 'Destroy', user_registration_path, :confirm => 'Are you sure you want to destroy your account?', :method => :delete %>

这是因为设计将注册注册为身份资源

It's because of devise treat registration as Singular Resource.

此外,运行 rake路线,您可以查看有关注册路由的详细信息:

Besides, run rake routes and you can see details about registration routing:

user_registration      POST   /users(.:format)                                       {:action=>"create", :controller=>"devise/registrations"}
new_user_registration  GET    /users/sign_up(.:format)                               {:action=>"new", :controller=>"devise/registrations"}
edit_user_registration GET    /users/edit(.:format)                                  {:action=>"edit", :controller=>"devise/registrations"}
user_registration      PUT    /users(.:format)                                       {:action=>"update", :controller=>"devise/registrations"}
user_registration      DELETE /users(.:format)                                       {:action=>"destroy", :controller=>"devise/registrations"}

这意味着:


  • user_registration_path 是一个帮助方法,返回 / users(.format)

  • 执行 DELETE 请求 / users(.format)将删除注册

  • user_registration_path is a helper method that returns /users(.format)
  • Perform DELETE request on /users(.format) will delete the registration

这篇关于破坏设备注册的途径是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆