Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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"
[..]

/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.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top