Rails:如何实现单属性AJAX更新?(Rails: How to implement single-attribute AJAX updates?)

在我的Rails应用程序中,我想要单属性AJAX更新,例如“单击表格中的行标签以切换公共/私有标志”。 实施此策略的最佳策略是什么? 在控制器或自定义方法中使用update方法?

In my Rails app, I want single-attribute AJAX updates e.g. "Click on row label in a table to toggle public/private flag". What's the best strategy for implementing this? Use the update method in controller or a custom method?


除非您有一些令人信服的理由使用自定义方法,否则只需使用正常更新,发送典型object[attr] = value有效负载。 它很简单,开箱即用,并且坚持REST。

Unless you have some compelling reason to use a custom method, just use the normal update, sending your typical object[attr] = value payload. It's simple, works out of the box, and adheres to REST.