Rails 5.1.2引导程序图标未在生产中提供 [英] Rails 5.1.2 bootstrap icons not being served in production

查看:79
本文介绍了Rails 5.1.2引导程序图标未在生产中提供的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This is an Awesome place. I hope to be competent enough soon to contribute solutions.

请,有人帮忙!!?!

我已经看了几个小时的youtube,并阅读了有关资产的每则帖子

I have watched hours of youtube and read every post about asset pipeline pre-compilation on the web.

出于某种原因,我决定使用Rails 5.1.2,但我不知道这是否是问题。

For whatever reason I decided to use Rails 5.1.2 and I don't know if that is the problem.

glyphicons不在Heroku上或使用

glyphicons don't render on Heroku or using

rails s -e production 

在我的本地ubuntu上。

on my local 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中我得到了

but in log/production.log I get


FATAL -:[849248f2-cd3c-4912-a10d-4f63bd5857ae] ActionController :: RoutingError(没有路线与[GET] / assets / glyphicons-halflings-regular.ttf匹配):

FATAL -- : [849248f2-cd3c-4912-a10d-4f63bd5857ae] ActionController::RoutingError (No route matches [GET] "/assets/glyphicons-halflings-regular.ttf"):

FATAL-:[dfae9054-ad8a-4553-85a3-c55d55b1946c] ActionController :: RoutingError(没有路线与[GET] / assets / glyphicons-halflings-regular.woff匹配):

FATAL -- : [dfae9054-ad8a-4553-85a3-c55d55b1946c] ActionController::RoutingError (No route matches [GET] "/assets/glyphicons-halflings-regular.woff"):

等...

我不明白吗?!?我不会假装理解资产管道的帽子下所有的伏都教徒,并且现在不想成为新手,而是!!!?为什么?有人可以告诉我吗?

Me no get?!? I won't pretend to understand all the voodoo goings on under the bonnet of the asset pipeline and want now to not be newbie but this!?!? Why? Can anyone let me know?

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

My /app/assets/stylesheets/bootstrap.css has been amended to show

@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');
}

,有趣的是 / assets / 部分被添加,即使我将其完全放在上述文件的url路径之外。我已经尝试了一切。有人可以帮忙吗?任何帮助将不胜感激。

and, interestingly enough the /assets/ part gets added even if I leave it out of the url path in the above file altogether. I have tried everything. Can anyone help? Any help would be much appreciated.

欢呼

推荐答案

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

If you wish to keep your assets in /assets folder only and not in /public folder.

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

Firstly, You can place all glyohicons' fonts file in /assets/fonts folder. (If /fonts not created, then create one).

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

Secondly, convert your .css file into .scss file by renaming it so that you can use assets_path method in stylesheet

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

Then, let your application know that you have fonts as an asset too by adding following line in your application.rb file

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

然后,更改您的网址通过以下方式在bootstrap.scss文件中。

Then, change your urls in bootstrap.scss file in a following way.

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

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

Restart the server and check, fonts should get loaded as assets.

谢谢。

这篇关于Rails 5.1.2引导程序图标未在生产中提供的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆