在Rails制作中使用boostrap.css文件/ heroku w / o LESS或SASS [英] Using boostrap.css file in Rails production/heroku w/o LESS or SASS
问题描述
我试图在我的rails 4.0beta1应用程序中使用bootstrap提供的glyphicons。在开发过程中,一切正常,但在生产中没有任何渲染,并在heroku日志中,我得到以下错误:
ActionController: :RoutingError No Route Matches [GET]/assets/glyphicons-halflings.png
这就是我在boostrap.css中调用图像文件:
[class ^ =icon-],
[class * =icon-] {
background-image:url(/ assets / glyphicons-halflings.png);
}
这就是我在视图中渲染它的方式:
< i class =icon-user>< / i>
运行rake资产时:预编译并使用rails s -e production启动生产服务器,然后我无法再看到图标。我不确定为什么会出现这种情况。我没有使用与bootstrap相关的任何宝石,我只有简单的bootstrap.css文件和资产/图像下的图像文件。
$ b 编辑:
我还添加了一个.erb扩展名(bootstrap.css.erb)以使用asset_path帮助程序,但我仍然只看到正在开发中的图标,而不是正在生成的图标。
有人有任何想法吗?
奇怪的是,背景图像在生产中似乎不起作用。我只是使用background:属性来加载其他背景图片,所以我尝试了这一点,现在它(神奇地)在生产中工作:
background:url(<%= asset_path'glyphicons-halflings.png'%>);
以bootstrap.css.erb作为文件名。
仍然困惑于为什么背景图像在开发中工作,而不是产品......
I'm trying to use the glyphicons provided by bootstrap in my rails 4.0beta1 app. Everything works fine in development, but in production nothing gets rendered, and in the heroku logs I get the following error:
ActionController::RoutingError No Route Matches [GET] "/assets/glyphicons-halflings.png"
This is how I'm calling the image file in boostrap.css:
[class^="icon-"],
[class*=" icon-"] {
background-image: url("/assets/glyphicons-halflings.png");
}
This is how I'm rendering it in the view:
<i class="icon-user"></i>
When I run rake assets:precompile and start up the production server with rails s -e production, then I can no longer see the icons. I'm not sure why this is the case. I'm not using any gems associated with bootstrap, I just have the plain bootstrap.css file and the image file under assets/images.
EDIT: I also added a .erb extension (bootstrap.css.erb) to use the asset_path helper, but I still only see the icons in development, not production.
Anybody have any ideas?
Well, oddly, background-image did not seem to work in production. I was loading other background images using just the background: property, so I tried that and now it (magically) works in production:
background: url(<%= asset_path 'glyphicons-halflings.png' %>);
with bootstrap.css.erb as the filename.
Still confused as to why background-image was working in development but not production ...
这篇关于在Rails制作中使用boostrap.css文件/ heroku w / o LESS或SASS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!