放置或修补新的更新操作 Rails

编程入门 行业动态 更新时间:2024-10-10 09:23:06
本文介绍了放置或修补新的更新操作 Rails的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在我的 rails 用户模型中添加一个新的 update(new_update) 操作,它将更新模型中的单个列.我应该在路由文件中使用哪个 rest api 方法.我应该使用 put 或 patch 还是两者都使用.

I want to add a new update(new_update) action in my user model of rails which will update a single column in the model. which rest api method I should use in routes file. Should I use put or patch or both.

resources: users do member do put 'new_update' patch 'new_update' end

推荐答案

如果你想 100% 匹配 HTTP 动词定义.

If you want to match 100% with the HTTP verb definition.

PUT 应该用请求中的内容完全覆盖您的目标资源(请求中不存在的所有字段都应设置为已删除/无效).

PUT is supposed to overwrite your targeted resource entirely with the content in the request(all field non present in the request should be set to removed/nullified).

PATCH 应该只修改请求中发送的字段.

PATCH is supposed to only modify the fields sent in the request.

话虽这么说,但大多数时候人们并没有区别并使用它们中的任何一个(很多人甚至不知道有 PATCH 动词)是使用具有与 PATCH 相同行为的 PUT(因为 PUT 的用例在 imo 上非常罕见).

That being said, most of the time people don't make the difference and use either of them (a lot of people don't even know that there is a PATCH verb) is use PUT with the same behavior as PATCH (since the use case for PUT is quite rare on imo).

更多推荐

放置或修补新的更新操作 Rails

本文发布于:2023-10-10 22:09:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479900.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:操作   Rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!