模块化页面布局

时间:2012-09-21 17:55:37

标签: ruby-on-rails

我想在我的应用程序的每个页面或几乎每个页面上显示某些内容。标题,页脚,侧边栏或导航等内容。

我该怎么做呢?我来自PHP和ColdFusion等语言,我要么包含文件,要么调用函数来显示我想要的内容。我很难理解如何在Rails中实现它。

2 个答案:

答案 0 :(得分:1)

通常在应用程序布局中,您使用partials。一个小例子看起来像

<body>
    <%= render :partial => 'shared/header' %>
    <%= yield %>
    <%= render :partial => 'shared/footer' %>
</body>

希望这有帮助。

答案 1 :(得分:0)

您的申请应该有app/view/layouts/application.html.erb。这就是你的html内容的用武之地。

在application.html.erb中,您应该看到<%= yield %>。这是具有相应视图的不同控制器操作的特定视图。

对于application.html.erb的css文件,您应该使用app/assets/stylesheets/application.css

对于application.html.erb的javascript文件,您应该使用app/assets/javascripts/application.js