问题描述
基于过去两天我一直在使用谷歌搜索功能,我加入了数百(如果不是数千)部署到Heroku时失去引导样式的人。就像其他所有人一样,引导程序样式在本地计算机上也可以正常工作,但在已部署的heroku站点上却不存在。我很沮丧。我正在使用Rails 4.2.4和ruby 2.2.3。 (如果这有所作为,我也使用RubyMine。我不认为这样做。我尝试使用简单的git和sublime进行部署,但没有任何区别。)这是我所做的:
Based on the googling I've been doing for the past two days, I am joining the hundreds (if not thousands) of people who lost bootstrap styling when deploying to Heroku. As is true of everyone else, the bootstrap styling works fine on the local machine, but is absent on the deployed heroku site. I am stumped. I am using rails 4.2.4 and ruby 2.2.3. (I am also using RubyMine if that makes a difference. I don't think it does. I tried a deploy with "plain" git and sublime and it made no difference.) Here is what I have done:
- 我在我的application.html.erb(css和js)中都有指向maxcdn的链接
- 我更改了application.css的名称为application.scss(我也尝试了application.css.scss)
- 我在@ application.scss中添加了@import指令(boostrap-sprockets和bootstrap)
- 我添加了// =要求bootstrap-sprockets到application.js(在turbolinks条目之后)。
- 我添加了gems bootstrap-sass,autoprefixer-rails ,和rails_12factor并捆绑安装了
- 我在config / environments / production.rb中将config.assets.compile从false更改为true。
- 我也我尝试过预编译资产,但引导样式仍然缺失。
- I have links to the maxcdn in my application.html.erb (both css and js)
- I changed the name of application.css to application.scss (and I also tried application.css.scss)
- I added the @import directives (boostrap-sprockets and bootstrap) to application.scss
- I added //= require bootstrap-sprockets to application.js (after the turbolinks entry).
- I added gems bootstrap-sass, autoprefixer-rails, and rails_12factor and did bundle install
- I changed config.assets.compile from false to true in config/environments/production.rb
- I also tried precompiling assets, but the bootstrap styling was still missing.
我相信这是我要做的所有工作。如上所述,它可以在本地计算机上正常工作。
I believe that is all I should have to do to get it working. As mentioned above, it works fine on the local machine.
我尝试了许多在网络上建议的无效解决方案。很难说出哪些是适用的,因为这似乎已经存在数年了(我的Google搜索从2012年至今一直返回这样的问题和建议的解决方案)。我确信其中一些解决方案不再适用(适用于Rails v4)。
I've tried many solutions suggested on the web that have not worked. It's hard to tell which ones are applicable because this seems to have been a problem for several years (my google searches return questions like this, and suggested solutions, from 2012 to the present). I'm sure some of those solutions are no longer applicable (for rails v4).
像往常一样,我们将提供任何帮助。
As usual, any help is appreciated.
推荐答案
尝试从头开始一个项目,并使Bootstrap在生产中正常工作。我用maxcdn方法成功做到了这一点。
Try to start a project from scratch and to just make Bootstrap working in production. I succeeded to do that with the maxcdn method.
这就是我包含bootstrap maxcdn的工作:
Here is what I did to include the bootstrap maxcdn :
app / views / layouts / application.html.erb ,在< head>
标记的末尾:
<!-- BOOTSTRAP -->
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"> </script>
我只是这样做,仅此而已。即使在Heroku上制作,它也像魅力一样发挥作用。
I only did this, and nothing else. It worked like a charm, even in production on Heroku.
这篇关于部署到Heroku后缺少引导样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!