从视图中排除 Rails CSS 文件
很抱歉问了这个奇怪的问题,但这让我想破脑袋。我的 Rails 应用程序中有一个名为 project.css 的文件,我不知道它是否与内置的 Rails 应用程序一起提供。与
我一起工作的一位程序员决定用通用样式填充它,这些样式影响了所有其他内容t 通过 id 或 class 分配自己的样式。
EG 他写道,
td
{
position:absolute;
top:20px;
font-family:Wingdings;
}
以便他的所有风格都复制到整个网站,包括我的页面。
我可以在页面中明确表示忽略此文件,而不是遍历所有页面并为需要使用的每个元素创建样式吗?
EG <% stylesheet_ignore_tag %>
它似乎默认包含样式表,所以问题是:
1:project.css 是rails 的一部分吗?如果没有的话我会质疑为什么网站上到处都是血。
2:我可以删除它或告诉我的页面不要加载它吗?
3:如果样式表没有忽略功能,有没有人知道如何修复它,而无需浏览每个页面并为他搞砸的每个元素制作样式?
我想我明白发生了什么。他将这个怪物般的 css 文件包含在 application.html.erb 文件中。这是整个站点共享的标头。这样,它似乎也影响了正在加载的所有单独页面。
Sorry for the odd question but this is one that makes me want to bust a head. Theres a file in my rails app called project.css and I don't know if it came with the rails application built in.
One of the programmers I'm working with decided to fill it with generic styles which have effected everything that wasn't assigned its own style by id or class.
EG he writes
td
{
position:absolute;
top:20px;
font-family:Wingdings;
}
So that all his style are replicated across the entire site including my pages.
rather than going through all my pages and creating styles for every element that I need to use, can I just explicit say in my pages to ignore this file?
EG <% stylesheet_ignore_tag %>
It seems to be including the stylesheet by default so the questions are:
1: Is the project.css part of rails. if not then I'd question why the hell its bleeding all over the site.
2: Can i get rid of it or tell my pages not to load it.
3: If theres no ignore feature for stylesheets has anyone got any ideas as to how to fix it without going through each page and making styles for each element he screwed up?
Think i figured out what happened. He included this monstrosity of a css file in the application.html.erb file. This is a header that's shared across all the site. This way it seems to have effected all the individual pages being loaded aswell.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该考虑对该 css 文件使用 content_for 。这样你就可以从布局中删除它,放置一个
<%= yield :specic_css %>
代替,并在使用该 css 的视图中使用 content_for :You should consider using content_for for that css file. This way you can remove it from the layout, put a
<%= yield :specific_css %>
instead and use content_for in the views that use that css this way:听起来它正在加载到通用布局文件中。
如果它真的没有被使用,除了让你的生活变得痛苦......为什么不直接从你的存储库中删除它呢? :)
更好的是——去问那个人他这样做是为了什么,以及你是否可以解决其他问题。
Sounds like it's being loaded in the general layout file.
If it's really not being used except to make life painful for you... why not just delete it from your repository? :)
Better yet - go ask the guy what he did that for and whether you can work something else out.