Sharing layout code among different controllers


#1

I want to have one layout for my whole application. The app
has multiple controllers. Is it true that layouts are associated
w/ one controller?
thanks, etienne


#2

I think all you need to do is:

layout “yourlayout”

on each controller

Frank

----- Original Message -----
From: “mizage” removed_email_address@domain.invalid
To: removed_email_address@domain.invalid
Sent: Friday, December 16, 2005 11:17 AM
Subject: [Rails] sharing layout code among different controllers


#3

ok just found the solution. According to the agile web dev book it says
“If you create a layout call ‘application’ in the ‘layouts’ directory,
it will be applied to all controllers that don’t otherwise have a layout
defined for them”


#4

Yes. But there is a solution. Make a layout called application.rhtml
and drop it in the root of the layouts folder. Your app always
checks for the existence of that file. There is a potential gotcha
here. If you also have a controller specific layout (made
automatically by scaffolding) it will OVERRIDE the application.rhtml
file.

bruce