【发布时间】:2015-09-22 19:57:06
【问题描述】:
我关注http://jsonapi.org/format/#document-top-level
我注意到以下终点(路线):
/articles/1/relationships/author
在 Rails 中,routes.rb 中如何构造这条路由?
resources :articles do
# What goes here?
# Should relationship be a namespace or other?
# I guess author can be defined as a collection, or just a simple get
end
relationships 不需要 7 个 RESTFUL 操作中的任何一个。
【问题讨论】:
-
取决于,您是否还有许多其他资源可以归入
/relationships?您的关联控制器(子文件夹?)在哪里,您的控制器操作是什么? -
可能不会,所以我猜
namespace :relationships do; get 'author'; end;应该没问题。这也意味着get 'author'路由将指向ArticlesController中的author操作。除非有办法让author操作存在于Relationships控制器中吗?我认为这有助于更好的逻辑抽象 -
也许值得研究一下您是否可以使用 routing concerns,因为在 API 的上下文中,您可以将其用于许多其他资源
标签: ruby-on-rails ruby-on-rails-4 json-api