按照关于嵌套资源路由的 Rails 指南,我有两个模型,我的路由如下:
# 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
andcreate
动作是正确嵌套的,但其他动作不是。谁能解释为什么会这样?