为什么我的一些Rails路径助手有一个_index后缀?

Cra*_*ker 14 routes ruby-on-rails

我有一个Rails路由定义,看起来像这样:

namespace :admin do
  resources :feeds
  resources :push
end
Run Code Online (Sandbox Code Playgroud)

rake routes 为它生成以下输出:

admin_feeds GET  /admin/feeds  {:controller=>"admin/feeds", :action=>"index"}
admin_push_index GET  /admin/push  {:controller=>"admin/push", :action=>"index"}
Run Code Online (Sandbox Code Playgroud)

为什么路径助手push会获得_index后缀,但不是feeds

iwa*_*bed 15

这一切都基于多个资源.因此,如果资源名称是复数,则不需要添加_index后缀,因为它是推断的.

如果它是一个单一的资源名称,那么它会添加后缀以便澄清,因为它admin_push通常是一个show动作而不是index动作.