Rails 关于 LIKE 的功能大家是怎样规划 restful 的?

lulalala · September 27, 2012 · Last by jokry replied at October 29, 2012 · 2648 hits

目前我们有个 likes table,是 polymorphic association 的一部分,许多 model 都能用这来作 like 的纪录。

目前的 route 用 nested resource 作:

POST   /items/:item_id/likes
DELETE /items/:item_id/likes/:id

总觉得想要把 delete 的 like_id 隐藏起来。

第一种方式是想说:不用 nested resource。作个 item/:item_id/like action 然后由 PUT 或 DELETE 来判断是哪种 like 动作,自行增减 like association 就好了。

第二种方法是想说,不要有特别的 route 了,设立一个 virtual attribute,直接用 update item 方式来设立 like。缺点就是所有 likable 的 model 都要这样设立。

请问大家对这两种设计的看法是,或是有更好的建议?

我是采用你说的第一种方式,这几种差异不大。

You need to Sign in before reply, if you don't have an account, please Sign up first.