Recipe 5.6. Defining a Default Application Layout


Problem

You want to create a consistent look across your entire application using a single layout template.

Solution

To apply one layout to every controller view by default, create a layout template named application.rhtml and put it in your application's layout directory (app/views/layouts). For example:

app/views/layouts/application.rhtml:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"                "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">   <title>My Weblog</title>   <head>     <meta http-equiv="Content-Type"                                 content="text/html; charset=ISO-8859-1" />     <%= stylesheet_link_tag "weblog" %>     <%= javascript_include_tag :defaults %>   </head>   <body>     <div >            <%= yield %>     </div>    </body> </html>

Discussion

The application-wide layout template in the solution will apply to all of your views by default. You can override this behavior per controller (or even per action) by creating additional layout files named after your controllers or by explicitly calling the layout method within your controller class definitions.

See Also

  • Section 5.5"




Rails Cookbook
Rails Cookbook (Cookbooks (OReilly))
ISBN: 0596527314
EAN: 2147483647
Year: 2007
Pages: 250
Authors: Rob Orsini

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net