Creating A Layout

Important files:

  • app/views/layouts/application.html.erb: This will be the default template used to layout all your web pages.
  • public/stylesheets/application.css: This will be our default css file. It does not have to be called application.css. We call it that because of the line stylesheet_link_tag 'application' in the layout.


codetitle. app/views/layout/application.html.erb

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<html xmlns="" xml:lang="en" lang="en">
  <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
  <title><%= controller.action_name %></title>
  <%= stylesheet_link_tag 'application' %>

<p style="color: green"><%= flash[:notice] %></p>

<%= yield  %>


A couple things to note:

  • the character encoding of your application will be UTF-8. This is a very good idea, although it will not really be true UTF-8 unless your database is also UTF-8.
  • The yield command will insert the result of the current view into this template.
  • The doctype is set to xhtml. This makes it so that the browser will be less forgiving if you include badly formatted html. In short, you must make sure that every time you open an html tag that you also close it!


nothing here yet.