不同的背景颜色为轨道不同的页面 [英] Different background color for different pages in rails

查看:150
本文介绍了不同的背景颜色为轨道不同的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我使用的是application.html.erb文件,它基本上是在我的网站的每个页面的布局。但我想的网页有一个白色的背景和页面的其余部分有不同的背景。问题是,如果我包住整个网页文件中的一个div,它只是包装了收益的地方,因此它显示为具有较大框内白色背景带有灰色背景框。那么,如何改变主页的整个背景,离开休息吗?

So I'm using an application.html.erb file which is basically the layout for every page in my website. But I want the homepage to have a white background and the rest of the pages to have a different background. The problem is, if I wrap the entire homepage file in a div, it only wraps the "yield" place and so it shows as a box with a white background within a larger box with a gray background. So how can I change the entire background of the homepage and leave the rest?

谢谢!

推荐答案

扩大对@muffinista给出了答案:
您可以使用实例变量集控制器,以确定何时把主页类对身体标记。所以:

Expanding on the answer provided by @muffinista: You can use an instance variable set in the controller to determine when to put the 'homepage' class on the body tag. So:

def index
  @home_page = true
  # existing code
end

和布局:

<body class="<%= @home_page ? 'homepage' : ''%>">
 <%= yield %>
</body>

这篇关于不同的背景颜色为轨道不同的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆