Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do some of my Rails path helpers have an _index suffix? [duplicate]

I have a Rails route definition that looks something like this:

namespace :admin do
  resources :feeds
  resources :push
end

rake routes generates the following output for it:

admin_feeds GET  /admin/feeds  {:controller=>"admin/feeds", :action=>"index"}
admin_push_index GET  /admin/push  {:controller=>"admin/push", :action=>"index"}

Why would would the path helper for push get the _index suffix, but not feeds?

like image 795
Craig Walker Avatar asked Dec 13 '11 21:12

Craig Walker


2 Answers

It's all based on the plurality of the resource. So if the resource name is plural, then it has no need to add an _index suffix since it's inferred.

If it is a singular resource name, then it adds the suffix for clarification since admin_push would typically be a show action instead of the index action.

like image 92
iwasrobbed Avatar answered Nov 15 '22 23:11

iwasrobbed


You can also use

resource :push

instead of

resources :push

to specify a singular resource. See http://api.rubyonrails.org/classes/ActionDispatch/Routing.html

like image 37
mshafrir Avatar answered Nov 15 '22 23:11

mshafrir