0
votes

routes.rb

resources :home do
 get 'download', :on => :collection
end

rake routes

download_home_index GET    /home/download(.:format)     home#download
home_index GET             /home(.:format)              home#index
....

home_controller.rb

def index
end

When i go to http://localhost:3000/home/download, it works even though there is no "download" action in the home_controller. I am confused why even without the action, it doesn't complain missing action.

I was curious so I added resources :homes to routes.rb and rake routes gave me the following:

homes GET    /homes(.:format)             homes#index

In comparison, it is not homes_index whereas it was home_index before. Is there some rails magic going on? Appreciate some explanation.

1

1 Answers

0
votes

For the first question, if you have a view for the action, you don't strictly need the action defined (but you really should).

For the second question, you defined resources :homes vs resources :home, hence the generated routes are different. resources :home is incorrect.