Rails 5.1.2引导程序图标未在生产中提供

这是一个很棒的地方。 我希望很快能够胜任,提供解决方案。

请有人帮忙!!?!

我已经看了几个小时的youtube并阅读了关于网上资产管道预编译的每篇文章。

无论出于何种原因,我决定使用Rails 5.1.2,我不知道这是不是问题。

glyphicons不会在Heroku上渲染或使用

rails s -e production 

在我当地的ubuntu上。

我打字

 rake assets:precompile RAILS_ENV=production 

得到

 I, [2018-01-01T16:05:07.261287 #4745] INFO -- : Writing /home/dracos/rails/video-store/public/assets/glyphicons-halflings-regular-e395044093757d82afcb138957d06a1ea9361bdcf0b442d06a18a8051af57456.ttf I, [2018-01-01T16:05:07.261968 #4745] INFO -- : Writing /home/dracos/rails/video-store/public/assets/glyphicons-halflings-regular-e395044093757d82afcb138957d06a1ea9361bdcf0b442d06a18a8051af57456.ttf.gz I, [2018-01-01T16:05:07.263049 #4745] INFO -- : Writing /home/dracos/rails/video-store/public/assets/glyphicons-halflings-regular-fe185d11a49676890d47bb783312a0cda5a44c4039214094e7957b4c040ef11c.woff I, [2018-01-01T16:05:07.264510 #4745] INFO -- : Writing /home/dracos/rails/video-store/public/assets/glyphicons-halflings-regular-fe185d11a49676890d47bb783312a0cda5a44c4039214094e7957b4c040ef11c.woff2 I, [2018-01-01T16:05:07.289833 #4745] INFO -- : Writing /home/dracos/rails/video-store/public/assets/application-c29c47294834d3d47956f910a3182df4a7db7d5864e82c6f758027f30669bafb.js I, [2018-01-01T16:05:07.290028 #4745] INFO -- : Writing /home/dracos/rails/video-store/public/assets/application-c29c47294834d3d47956f910a3182df4a7db7d5864e82c6f758027f30669bafb.js.gz I, [2018-01-01T16:05:14.175848 #4745] INFO -- : Writing /home/dracos/rails/video-store/public/assets/application-b896db4d9b9e69049347e71a1825dcdc1a4eed9147196fdd761afe6f12b556d4.css I, [2018-01-01T16:05:14.176068 #4745] INFO -- : Writing /home/dracos/rails/video-store/public/assets/application-b896db4d9b9e69049347e71a1825dcdc1a4eed9147196fdd761afe6f12b556d4.css.gz 

但是在log / production.log中我得到了

致命 – :[849248f2-cd3c-4912-a10d-4f63bd5857ae] ActionController :: RoutingError(没有路由匹配[GET]“/assets/glyphicons-halflings-regular.ttf”):

致命 – :[dfae9054-ad8a-4553-85a3-c55d55b1946c] ActionController :: RoutingError(没有路由匹配[GET]“/assets/glyphicons-halflings-regular.woff”):

等等…

我没有得到?!? 我不会假装理解资产管道的引擎盖下的所有伏都教,并且现在想要不是新手而是这个!?!? 为什么? 任何人都可以让我知道吗?

我的/app/assets/stylesheets/bootstrap.css已修改为显示

 @font-face { font-family: 'Glyphicons Halflings'; src: url('../assets/glyphicons-halflings-regular.eot'); src: url('../assets/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('../assets/glyphicons-halflings-regular.woff2') format('woff2'), url('../assets/glyphicons-halflings-regular.woff') format('woff'), url('../assets/glyphicons-halflings-regular.ttf') format('truetype'), url('../assets/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg'); } 

并且,有趣的是,即使我将它完全从上述文件中的url路径中删除,也会添加/assets/ part。 我尝试了一切。 有人可以帮忙吗? 任何帮助将非常感激。

干杯

如果您希望仅将资产保留在/ assets文件夹中而不保留在/ public文件夹中。

首先,您可以将所有glyohicons的字体文件放在/ assets / fonts文件夹中。 (如果未创建/ fonts,则创建一个)。

其次,通过重命名将.css文件转换为.scss文件,以便在样式表中使用assets_path方法

然后,通过在application.rb文件中添加以下行,让您的应用程序知道您也将字体作为资产

 config.assets.paths << "#{Rails.root.to_s}/app/assets/fonts" 

然后,以下列方式更改bootstrap.scss文件中的URL。

 src: url(asset_path('glyphicons-halflings-regular.eot')); 

重新启动服务器并检查,字体应作为资产加载。

谢谢。

您可以编写资产管道,您可以将您的字体文件移动到公共文件夹,例如public/assets命名fonts create folder,查看public/assets/fonts/然后上传您的字体文件,这看起来像public/assets/fonts/glyphicons-halflings-regular.woff和更改路径,如/assets/fonts/glyphicons-halflings-regular.woff/assets/glyphicons-halflings-regular.wof

希望能有所帮助

你可以用这种方式解决这个问题 –

  1. 在app / assets目录中创建一个文件夹名称“fonts”,并在fonts目录中放置引导字体(glyphicons-halflings-regular.eot,glyphicons-halflings-regular.ttf,glyphicons-halflings-regular.woff等)字体。
  2. 现在将此行添加到config / application.rb

     config.assets.paths << Rails.root.join("app", "assets", "fonts") 
  3. 现在你必须将app / assets / stylesheets / application.css重命名为app / assets / stylesheets / application.css.scss并放置以下代码 -

     @font-face { font-family: 'Glyphicons Halflings'; src: url(asset-path("glyphicons-halflings-regular.eot")); src: url(asset-path("glyphicons-halflings-regular.eot?#iefix")) format("embedded-opentype"), url(asset-path("glyphicons-halflings-regular.woff2")) format("woff2"), url(asset-path("glyphicons-halflings-regular.woff")) format("woff"), url(asset-path("glyphicons-halflings-regular.ttf")) format("truetype"), url(asset-path("glyphicons-halflings-regular.svg#glyphicons_halflingsregular")) format("svg"); } 
  4. 现在将字体添加到config / initializers / assets.rb以预编译其他资产。

     Dir.glob("#{Rails.root}/app/assets/fonts/**/").each do |path| Rails.application.config.assets.paths << path end 
  5. 重新启动Web服务器。

我希望它现在应该有效。

基于fool-dev的回答……使用Rails 5.1.4, yarnwebpacker ……所需要的只是将bootstrap字体文件从bootstrap/dist/fonts/复制到public/fonts并重新部署。

根本没有弄乱提供的bootstrap/dist/css/bootstrap.*文件。