10

I noticed that an index view is routed correctly even if there isn't a controller method index.

As an example, the routes.rb has this route

AppName::Application.routes.draw do
  get 'about' => "about#index"
end

My controller looks like this with no index method (def index end)

class AboutController < ApplicationController
end

and I have a view called index.html.erb in the views/about folder

What's happening here? Is this a case of rails magic where they automatically show the view even if there is no controller method? I couldn't find any documentation on this...

Joe Kennedy
  • 9,365
  • 7
  • 41
  • 55
hajpoj
  • 13,299
  • 2
  • 46
  • 63
  • 4
    Yeah, that's new; the controller docs have not been updated to reflect this yet--the docs imply you still need an empty method. – Dave Newton Dec 22 '11 at 04:54
  • 1
    Wow ! I run into a security issue with a forgotten view, that was suddenlt exposed... looking forward to override this behaviour! – dgilperez Jan 08 '12 at 01:07

1 Answers1

13

If you have the view file, it'll go ahead and render that implicitly, as documented here

See also, this SO thread on how Rails renders your view files and controller actions.

Community
  • 1
  • 1
sczizzo
  • 3,196
  • 20
  • 28