1
votes

I did

rails generate controller home index

But it adds this line to my routes.rb

get "home/index"

I thought Rails could deduce controller/method from the URL automatically? Why do I need to specify every get/post page?

Here's my complete routes.rb file:

Callisto2::Application.routes.draw do
  root :to => "home#index"
  resources :assets
end

root "/" works fine. so does /assets/*.

What's the problem with /home/index? I get the error:

Routing Error

No route matches [GET] "/home/index"

Try running rake routes for more information on available routes.

rake routes (run as apache user) gives me the following output:

root  / home#index

Thanks for any clarifications. Not sure what I'm missing.

Edit: I didn't make this clear: I manually removed get /home/index from routes.rb to keep that file clean.

2

2 Answers

4
votes

Rails used to add the so called catch all route at the bottom of your routes file:

match ':controller(/:action(/:id(.:format)))'

There was nothing 'automatic' or magical about these urls, just that every rails app started out with this route in their routes.rb

This has fallen out of favour, at least partially because it makes everything accessible over get, whereas

resources :books

Adds each route with the appropriate http verb. Listing routes explicitly is also a lot less verbose than when rails started out.

1
votes

If your controller is home and the action is index your path is just /home.

You can find more information here.