Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: how to add a header to every page

What is the standard way to add a header and footer to every view in a Rails app?

like image 573
Drew Johnson Avatar asked May 25 '10 01:05

Drew Johnson


2 Answers

If this file is found, it will be used.

app/views/layouts/application.html.erb

<!doctype html>
<html>
  <head>
    <!-- stuff -->
  </head>
  <body>
    <!-- this is where content will be rendered -->
    <%= yield %>
  </body>
</html>

Otherwise, you can call in a different one.

# app/controllers/birds_controller.rb
class BirdsController < ApplicationController

  layout :birds   # looks for app/views/layouts/birds.html.erb

  # ...
end
like image 151
maček Avatar answered Oct 14 '22 05:10

maček


put the header and footer into the application layout which can be found at app/views/layouts/application.html.erb.You may have to create this file first.

like image 29
x1a4 Avatar answered Oct 14 '22 03:10

x1a4