views:

377

answers:

3

Is there a simple way to define a master template for my whole rails application? If not, what's the best way to reuse my templates so that I'm not copy and pasting the same template into a bunch of layout files?

+8  A: 

You can name it application.html.erb and Rails will use it for the whole app. More info at rails guides.

Anton Mironov
A: 

/app/views/layouts/whatever.rhtml (or whichever extension your prefer to work with):

<html>
 ...
   <%= yield %>
 ...
</html>

/app/controllers/ApplicationController.rb:

layout "whatever"

(Edit: I can't remember off the top of my head whether calling the layout application.rhtml (or whatever) automatically makes it the default layout for any controller lacking specification or whether this bit of magic is incorporated into the default ApplicationController when you generate scaffolding, using the above syntax.)

Patrick McKenzie
A: 

Create an application.html.erb file in the layout folder of the views. It will be called if the controller has no template, so you might need to remove them.

You can also define a template for a specific controller going

class FaqentriesController < ApplicationController
    layout "admin"
[..]
marcgg