我目前正在使用Heroku 知识库中推荐的这种配置来使用 Compass 和 Heroku。Heroku 有一个只读文件系统,因此编译后的样式表需要存储在 /tmp 中。这在 Heroku 上远程工作得很好;然而,在本地,Rails 期望在 /public/stylesheets 中找到样式表(当通过 调用时= stylesheet_link_tag 'screen.css', :media => 'screen, projection'
)。
为了解决这个问题,我在 /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
任何帮助将不胜感激。