【问题标题】:Using boostrap.css file in Rails production/heroku w/o LESS or SASS在 Rails 生产/heroku 中使用 bootstrap.css 文件而不是 LESS 或 SASS
【发布时间】:2013-06-18 03:44:56
【问题描述】:

我正在尝试在我的 rails 4.0beta1 应用程序中使用 bootstrap 提供的字形图标。在开发中一切正常,但在生产中没有任何渲染,并且在 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 assets:precompile 并使用 rails s -e production 启动生产服务器时,我再也看不到图标了。我不确定为什么会这样。我没有使用任何与 bootstrap 相关的 gem,我只有简单的 bootstrap.css 文件和 assets/images 下的图像文件。

编辑: 我还添加了一个 .erb 扩展名 (bootstrap.css.erb) 来使用 assets_path 帮助程序,但我仍然只能看到开发中的图标,而不是生产中的图标。

有人有什么想法吗?

【问题讨论】:

    标签: ruby-on-rails twitter-bootstrap heroku asset-pipeline ruby-on-rails-4


    【解决方案1】:

    嗯,奇怪的是,背景图像在生产中似乎不起作用。我只使用 background: 属性加载其他背景图像,所以我尝试了,现在它(神奇地)在生产中工作:

    background: url(<%= asset_path 'glyphicons-halflings.png' %>);
    

    以 bootstrap.css.erb 作为文件名。

    仍然对为什么 background-image 在开发中工作而不是在生产中工作感到困惑......

    【讨论】:

      【解决方案2】:

      试试这个简单的方法:

      background-image: url('gliphicons-halflings.png')
      

      编辑:glyphicons.scc.scss.erb

      @font-face {
      font-family: 'Glyphicons';
      src: url('<%= asset_path('glyphicons-regular.eot')%>');
      src: url('<%= asset_path('glyphicons-regular.eot?#iefix')%>') format('embedded-opentype'), url('<%= asset_path('glyphicons-regular.woff')%>') format('woff'), url('<%= asset_path('glyphicons-regular.ttf')%>') format('truetype'), url('<%= asset_path('glyphicons-regular.svg#glyphicons_halflingsregular')%>') format('svg');
      font-weight: normal;
      font-style: normal;
      }
      
      [class^="glyphicons-"]:before {
      display: inline-block;
      font-family: 'Glyphicons';
      font-style: normal;
      font-weight: normal;
      text-decoration: inherit;
      *display: inline;
      *zoom: 1;
      

      }

      【讨论】:

      • 只是好奇,您在项目中使用文件glyphicons.css.scss.erb 吗? @font-face 应该有一个关于字形图标的定义。
      • 不,我不知道。只有 bootstrap.css 文件和 glyphicon 图像文件。
      • 我想你们两个可能在讨论两种不同版本的 bootstrap,Rumen 从 Bootstrap 3 的角度来回答。
      猜你喜欢
      • 2014-05-04
      • 1970-01-01
      • 2020-11-20
      • 1970-01-01
      • 2015-03-16
      • 2012-12-26
      • 2014-01-05
      • 2016-04-28
      • 1970-01-01
      相关资源
      最近更新 更多