简体   繁体   English

在Ruby on Rails中删除用户的个人资料时出错

[英]Errors in deleteing user's profile in Ruby on Rails

Controller(Users) and Action:- 控制器(用户)和操作:

def destroy

@user=User.find(params[:id]).destroy

flash[:success] = "Your account has been deleted."

redirect_to(root_path)

end

routes.rb routes.rb

match '/destroy', to: 'users#destroy'
*#(resources:users)* have already mentioned

views: 观点:

<%= link_to 'Delete', @user, confirm: 'Are you sure?', method: :delete %>

NOW, Everything is going fine till the message box "confirm: 'Are you sure?'" and then when I clicking "OK" gives me two notices one highlighted with yellow "You are not authorized to access this page". 现在,一切正常,直到出现“确认:'您确定吗?'”消息框,然后当我单击“确定”时 ,我有两个提示以黄色突出显示“您无权访问此页面”。

and other with green "You have to confirm your account before continuing" . 以及其他带有绿色的“您必须先确认您的帐户,然后才能继续”

Please reply as soon as possible. 请尽可能尽快回复。

Thank you!!!! 谢谢!!!!

Your link_to will not generate a link to the '/destroy' you mentioned in the routes.rb, but to /user/1. 您的link_to不会生成到您在route.rb中提到的'/ destroy'的链接,而是到/ user / 1的链接。 But that should not interfere when you used the 'resources', where also a delete action is defined. 但这在您使用“资源”(定义了删除操作)时不会造成干扰。

Second: check your Ruby/Rails version. 第二:检查您的Ruby / Rails版本。 The link_to has undergone some changes to v3 that could cause this behaviour. link_to对v3进行了一些更改,可能会导致此行为。

Check where those yellow and green messages are displayed. 检查这些黄色和绿色消息的显示位置。 Probably in VIEWING the user instead of deleting it. 可能是在查看用户时删除了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM