我是 Rails 的新手,我正在尝试了解 Rails 在多大程度上支持使用 HTTP 电子标签的条件 GET 和条件 PUT。
看来Rails的“新鲜”?方法支持条件 GET(If-None-Match header ),但不支持条件 PUT(If-Match header )。看来这是因为“新鲜”?使用“etag_matches?”,它只查看 If-None-Match header 。
阅读了源代码后,我想我可以自己实现条件 PUT。我只是想知道 Rails 是否以一种我还没有发现的方式开箱即用地支持它。
谢谢!
最佳答案
e-tags are not only for caching, but also for concurrency control. If someone has updated the resource on the server since the client has read it, the update should not succeed if you care about proper concurrency control.
如果您希望阻止某人在另一次更新后更新模型,您需要自己添加。您可以自己查看 etag 和 header ,因此辅助方法可能是可行的方法。
关于ruby-on-rails - Rails 3.1 是否像支持条件 GET 一样支持条件 PUT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8915516/