“删除”动作发生两次?
我的文件控制器的删除操作遇到了奇怪的情况。
Started GET "/files/35/delete" for 127.0.0.1 at 2011-02-27 01:13:51 -0500
Processing by FilesController#delete as HTML
Parameters: {"id"=>"35"}
SQL (0.3ms) DELETE FROM `files` WHERE (`files`.`id` = 35)
SQL (0.7ms) COMMIT
Redirected to http://localhost:3000/files
Completed 302 Found in 713ms
Started GET "/files/35/delete" for 127.0.0.1 at 2011-02-27 01:13:52 -0500
Processing by FilesController#delete as HTML
Parameters: {"id"=>"35"}
...leads to error
控制器操作:
@file = @company.files.where("id = ?", params[:id]).first
@file.destroy
flash[:notice] = "Your file was deleted successfully."
redirect_to files_url
路线:
resources :files do
member do
get 'delete_ask'
get 'delete'
end
end
你知道为什么会发生这种情况吗?
I have a strange situation with the delete action of my files controller.
Started GET "/files/35/delete" for 127.0.0.1 at 2011-02-27 01:13:51 -0500
Processing by FilesController#delete as HTML
Parameters: {"id"=>"35"}
SQL (0.3ms) DELETE FROM `files` WHERE (`files`.`id` = 35)
SQL (0.7ms) COMMIT
Redirected to http://localhost:3000/files
Completed 302 Found in 713ms
Started GET "/files/35/delete" for 127.0.0.1 at 2011-02-27 01:13:52 -0500
Processing by FilesController#delete as HTML
Parameters: {"id"=>"35"}
...leads to error
The controller action:
@file = @company.files.where("id = ?", params[:id]).first
@file.destroy
flash[:notice] = "Your file was deleted successfully."
redirect_to files_url
Routes:
resources :files do
member do
get 'delete_ask'
get 'delete'
end
end
Do you know why this is happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑这是由于重复提交请求而发生的。尝试通过 javascript 在客户端或服务器端防止双重提交(这将需要比客户端更多的努力,但更强大)。
I suspect that this happens due to double submit of the request. Try to prevent the double submits either at the client side through javascript or on the server side (which will require some more effort than the client side but more robust).
您可以
拯救
错误:You can
rescue
from errors: