如何消除rails erb文件中的重复代码

时间:2012-12-19 08:28:26

标签: ruby-on-rails erb railstutorial.org

如何消除正在发生的双重代码?

在about.html.erb中,我有以下代码:

<!DOCTYPE html>
<html>
<head>
    <title>Ruby on Rails Tutorial Sample App | <%= @title %></title>
</head>
<body>
    <h1>Pages#about</h1>
    <p>Find me in app/views/pages/about.html.erb</p>
</body>
</html>

在localhost:3000 / pages / about

的浏览器中
<!DOCTYPE html>
<html>
<head>
  <title>SampleApp</title>
  <link href="/stylesheets/application.css" media="all" rel="stylesheet" type="text/css" />
  <script src="/javascripts/application.js" type="text/javascript"></script>
  <meta content="authenticity_token" name="csrf-param" />
<meta content="ra/NXpqBo1ccudzQ2HGHoo3OrZB2bLX732MQl+EJHU4=" name="csrf-token" />
</head>
<body>

<!DOCTYPE html>
<html>
<head>
    <title>Ruby on Rails Tutorial Sample App | About</title>
</head>
<body>
    <h1>Pages#about</h1>
    <p>Find me in app/views/pages/about.html.erb</p>
</body>
</html>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

副本是app / views / layouts / application.html.erb

的一部分