我目前在Heroku中使用Compaoku,使用Heroku知識庫中推薦的configuration。 Heroku有一個只讀文件系統,因此編譯的樣式表需要存儲在/ tmp中。這在Heroku上可以很好地工作。然而,本地Rails希望在/ public/stylesheets中找到樣式表(當通過= stylesheet_link_tag 'screen.css', :media => 'screen, projection'
調用時)。在Heroku上使用Compass:/ tmp用於遠程和本地樣式表
爲了解決這個問題,我已經在/ public/stylesheets中使用ln -s tmp/stylesheets/screen.css public/stylesheets/screen.css
創建了符號鏈接,這似乎工作。
有沒有辦法解決這個問題,而不使用符號鏈接,也許通過更改Rails中的某些配置?我沒有取得太大的成功。
這裏是我的配置/初始化/ compass.rb:
require 'compass'
require 'compass/app_integration/rails'
Compass::AppIntegration::Rails.initialize!
# Required for Heroku:
require 'fileutils'
FileUtils.mkdir_p(Rails.root.join("tmp", "stylesheets"))
Compass::AppIntegration::Rails.initialize!
Rails.configuration.middleware.delete('Sass::Plugin::Rack')
Rails.configuration.middleware.insert_before('Rack::Sendfile', 'Sass::Plugin::Rack')
Rails.configuration.middleware.insert_before('Rack::Sendfile', 'Rack::Static',
:urls => ['/stylesheets'],
:root => "#{Rails.root}/tmp")
這裏是我的配置/ compass.rb:
project_type = :rails
project_path = Compass::AppIntegration::Rails.root
# Set this to the root of your project when deployed:
http_path = "/"
# Necessary for Heroku (original commented out:
css_dir = 'tmp/stylesheets'
#css_dir = "public/stylesheets/compiled"
sass_dir = 'app/views/stylesheets'
environment = Compass::AppIntegration::Rails.env
任何幫助將不勝感激。
這是否與rails3一起工作? – anka 2011-03-24 23:29:05
是的 - 我在Rails 3.0.5上。 – jdc 2011-03-25 16:50:14
在這個解決方案中我不明白的一件事就是爲什麼你要改變基於環境的「sass_dir」。這不是你存放源文件的地方嗎?爲什麼它在prod/heroku中會比在dev中有所不同?另外,你正在調用Compass :: AppIntegration :: Rails.initialize!兩次。 – 2011-06-02 14:27:13