ネストされたリソースのルーティングに関するRailsガイドに従って、2つのモデルと私のルートが次のようになります:
# media.rb
class Media < ActiveRecord::Base
has_many :captions, class_name: "Captions", dependent: :destroy
end
# captions.rb
class Captions < ActiveRecord::Base
belongs_to :media
end
# routes.rb
resources :medias do
resources :captions
end
実行するrake routes | grep captions
と、次のようになりますが、これは正しくないようです。私のアクションのいくつかは、私が期待するようにネストされていません:
media_captions GET /medias/:media_id/captions(.:format) captions#index
POST /medias/:media_id/captions(.:format) captions#create
new_media_caption GET /medias/:media_id/captions/new(.:format) captions#new
edit_captions GET /captions/:id/edit(.:format) captions#edit
captions GET /captions/:id(.:format) captions#show
PUT /captions/:id(.:format) captions#update
DELETE /captions/:id(.:format) captions#destroy
ご覧のとおり、index
およびcreate
アクションは適切にネストされていますが、他のアクションはネストされていません。なぜこれが起こっているのか誰でも説明できますか?