Rails 资产预编译问题
我确信我只是以错误的方式这样做,但我无法让它与资产一起使用:预编译,我不确定它应该是均匀的。
#plant.css.erb
<%
plants = Plant.all
if plants
plants.each do |plant|
%>
.plant_<%= plant.id %> {
background-color: #<%= plant.color %>;
padding: 1px;
}
<%
end
end
%>
我收到此错误:
Invalid CSS after "...kground-color: ": expected expression (e.g. 1px, bold), was "#;"
/rails/ship/releases/20111006191503/app/assets/stylesheets/application.css)
我感谢任何人可以提供的任何帮助。如果我没有提供足够的信息,请告诉我我需要什么,我很乐意提供。
I am certain I am just doing this the wrong way, but I cant get this to work with assets:precompile and im not sure it should be even.
#plant.css.erb
<%
plants = Plant.all
if plants
plants.each do |plant|
%>
.plant_<%= plant.id %> {
background-color: #<%= plant.color %>;
padding: 1px;
}
<%
end
end
%>
I get this error:
Invalid CSS after "...kground-color: ": expected expression (e.g. 1px, bold), was "#;"
/rails/ship/releases/20111006191503/app/assets/stylesheets/application.css)
I appreciate any help that anyone can give. If I did not provide enough info, let me know what I need and I will gladly provide it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定你的语法有什么问题,但整个方法似乎有点偏离规范。通常,人们不会为每个对象创建新的 CSS 规则。为什么不在
你的 CSS 文件(不需要 ERB)中定义一些类,
也许你不这样做是因为不同颜色的植物数量不是有限的?例如,你有彩虹般的颜色吗?在这种情况下,“老派”并使用 style 标签确实更合适:
I'm not sure what's wrong with your syntax, but the approach as a whole seems a bit upside down from the norm. Typically one would not create a new CSS rule for each object. Why not something like
and then in your CSS file (no need for ERB) define just a few classes
Maybe you're not doing that because there are not a finite number of different colored plants? E.g. you have a whole rainbow of colors? In that case, it's really more appropriate to go "old school" and use the style tag: