現在、Herokuナレッジベースで推奨されているこの構成を使用して、HerokuでCompassを使用しています。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の構成を変更することで、シンボリックリンクを使用せずにこの問題を解決する方法はありますか?私はあまり成功せずに突っついた。
これが私のconfig/initializers /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")
そして、これが私のconfig/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
どんな助けでも大歓迎です。