Rails:如何为每个页面添加标题

Dre*_*son 18 ruby-on-rails header footer code-standards

在Rails应用程序中为每个视图添加页眉和页脚的标准方法是什么?

mač*_*ček 26

如果找到此文件,将使用它.

应用程序/视图/布局/ application.html.erb

<!doctype html>
<html>
  <head>
    <!-- stuff -->
  </head>
  <body>
    <!-- this is where content will be rendered -->
    <%= yield %>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

否则,您可以拨打另一个电话.

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

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

  # ...
end
Run Code Online (Sandbox Code Playgroud)


x1a*_*1a4 9

将页眉和页脚放入应用程序布局中,该布局可以在app/views/layouts/application.html.erb中找到.您可能必须先创建此文件.