0

私は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

relationships7 つの RESTFUL アクションのいずれも必要ありません。

4

3 に答える 3

2

ルートは次のコード スニペットのようになります。

resources :articles do
   resources :relationships, :only => [] do
     collection do 
       get :author
     end
   end
end

ルート ファイルは次のようになります。更新が必要な場合はお知らせください。

于 2015-07-05T17:19:35.300 に答える
2

おそらくいくつかのリソースでこれを使用する必要があるため、私の懸念のアイデアに跳ね返ります(レールドキュメントは非常によく書かれています

concern :has_author do
  scope '/relationships' do
    resource :author
  end
end

resources :articles, concerns :has_author

これはに相当します

resources :articles do
  scope :'/relationships' do
    resource :author
  end
end
于 2015-07-05T17:29:24.390 に答える