2012-03-05 27 views
4

我最近在Heroku中添加了一個項目。但是,.css文件或.js文件似乎都不起作用。Heroku不顯示(查找?).css和.js文件

我正在使用Twitter的Bootstrap .css和.js文件。我已將這些文件添加到供應商/資產中的各自目錄。

基於我在這裏看到的其他問題,我在這裏問了一些問題,我在Heroku上從Bamboo升級到Cedar。我也嘗試rake assets:precompile RAILS_ENV=production,將config.assets.enabled = true更改爲config.assets.enabled = false in application.rb,config.assets.compile = falseconfig.assets.compile = true in production.rb,以及我想到的上述事物的組合。

一切工作正常本地。

(將鏈接添加到GitHub上,試圖提供更多的信息。) https://github.com/moctopus/sixtydays

回答

7

默認assets:precompile不會處理在/供應商/資產的CSS/JS文件。在production.rb中,您可以使用config.assets.precompile獲取由資源預編譯處理的其他css/js文件。

例如,如果您有內部/vendor/assets/bootstrap使用你的Twitter引導CSS/JS文件:

config.assets.precompile += %w[ bootstrap/*.css bootstrap/*.js ] 

然後rake assets:precompile會處理他們,他們會在Heroku工作。


見:http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets

編譯文件的默認匹配包括的application.js, application.css和所有非JS/CSS文件

+0

我仍然有不運氣。我已經預編譯了特定的文件並推送了它們。我也這樣做了,「在config/application.rb中將config.assets.initialize_on_precompile設置爲false」 – moctopus 2012-03-05 19:58:01

+0

以下是我的完整production.rb文件的示例:http://pastebin.com/hVEUvH6G(我使用默認的不變的應用程序.RB)。我在'/ vendor/assets/blueprint'中擁有資源,並使用'config.assets.precompile + =%w [blueprint/*。css]'在該文件夾中添加css。運行rake資源後:預編譯他們在heroku雪松上工作。你的資產實際上是被編譯/移動到/ public/assets(並提交到版本控制)? – pjumble 2012-03-05 20:09:26

+0

我只是使用默認的application.rb嘗試了幾個不同的東西。我嘗試過'config.assets.precompile + =%w [bootstrap.css]','config.assets.precompile + =%w [stylesheets/*。css]','config.assets.precompile + =%w [ * .css]'。我已經確認,當「rake資產:預編譯」運行時,文件正在創建並移動到公共/資產。我也證實他們在源代碼控制。仍然沒有運氣。 – moctopus 2012-03-05 20:45:01