-
Notifications
You must be signed in to change notification settings - Fork 0
rails default application layout
This is a guide for developers using the example apps from the Rails Apps repository. Others may find it helpful as well.
If you are creating an application template, this step uses the application_layout recipe from the rails_apps_composer repository.
Rails will use the layout defined in the file app/views/layouts/application.html.erb or app/views/layouts/application.html.haml as a default for rendering any page.
You’ll want to include flash messages for errors and notifications. Set up your application layout by modifying the default as described below.
Include flash messages in app/views/layouts/application.html.erb like this:
<body>
<%- flash.each do |name, msg| -%>
<%= content_tag :div, msg, :id => "flash_#{name}" if msg.is_a?(String) %>
<%- end -%>
<%= yield %>
For Haml, modify app/views/layouts/application.html.haml like this:
%body
- flash.each do |name, msg|
= content_tag :div, msg, :id => "flash_#{name}" if msg.is_a?(String)
= yield
The Rails 3.1 modified application layout app/views/layouts/application.html.erb will look like this:
<!DOCTYPE html>
<html>
<head>
<title>My App</title>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<%- flash.each do |name, msg| -%>
<%= content_tag :div, msg, :id => "flash_#{name}" if msg.is_a?(String) %>
<%- end -%>
<%= yield %>
</body>
</html>
If you are using Haml, remove app/views/layouts/application.html.erb and replace it with app/views/layouts/application.html.haml:
$ rm public/index.html
For Haml, the Rails 3.1 modified application layout app/views/layouts/application.html.haml will look like this:
!!!
%html
%head
%title My App
= stylesheet_link_tag :application
= javascript_include_tag :application
= csrf_meta_tags
%body
- flash.each do |name, msg|
= content_tag :div, msg, :id => "flash_#{name}" if msg.is_a?(String)
= yield
The Rails 3.0 modified application layout app/views/layouts/application.html.erb will look like this:
<!DOCTYPE html>
<html>
<head>
<title>My App</title>
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
</head>
<body>
<%- flash.each do |name, msg| -%>
<%= content_tag :div, msg, :id => "flash_#{name}" if msg.is_a?(String) %>
<%- end -%>
<%= yield %>
</body>
</html>
If you are using Haml, remove app/views/layouts/application.html.erb and replace it with app/views/layouts/application.html.haml:
$ rm public/index.html
For Haml, the Rails 3.0 modified application layout app/views/layouts/application.html.haml will look like this:
!!!
%html
%head
%title My App
= stylesheet_link_tag :all
= javascript_include_tag :defaults
= csrf_meta_tag
%body
- flash.each do |name, msg|
= content_tag :div, msg, :id => "flash_#{name}" if msg.is_a?(String)
= yield