application.rhtml

Subscribe to application.rhtml 3 post(s), 3 voice(s)

 
Avatar Roupen 84 post(s)

On page 37, we created application.rhtml to hold some layout info.

Is the name “application” special in any way – is it specified somewhere? Whats the convention on this :)

I thought maybe its /controllers/application.rb but I’m looking at an app (not in the book) where the file under /layouts is called something else (though it has /controllers/application.rb

Thanks

 
Avatar stranger 46 post(s)

application.rhtml is a layout for the whole application. Since it is the base file for the whole application we include the common parts of all the pages i.e header, footer, meta, scripts and css.

 
Avatar EldonAlameda Administrator 216 post(s)

Layouts are a fun topic – the way they work is that if there is a layout template in /app/views/layouts/ with the same name as the current controller then Rails will automatically use that layout file.

So if you have a PostController – Rails will look in /app/views/layouts for a post.rhtml file.

If it doesn’t find one with the same name as the controller then it will look for one named application.rhtml as a global layout.

Or you could also override which layout will be used by explicitly specifying it in the controller

class PostController < ActionController::Base
    layout "mylayout"