5

現在、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

どんな助けでも大歓迎です。

4

3 に答える 3

5

私は実際、HerokuでホストされているRailsアプリケーションを使用してCompassをセットアップしようとしていたので、これを実行するための言い訳を与えてくれてありがとう。:)

答えは簡単です。

'config / compass.rb'を変更します:

project_type = :rails
project_path = Compass::AppIntegration::Rails.root

http_path = "/"

environment = Compass::AppIntegration::Rails.env
if environment == 'production'
  css_dir = "tmp/stylesheets"
  sass_dir = "app/views/stylesheets"
else
  css_dir = "public/stylesheets"
  sass_dir = "app/stylesheets"
end

次に、「config / initializers/compass.rb」を変更します。

require 'compass'
require 'compass/app_integration/rails'
Compass::AppIntegration::Rails.initialize!

require 'fileutils'
FileUtils.mkdir_p(Rails.root.join("tmp", "stylesheets"))

environment = Compass::AppIntegration::Rails.env
if environment == 'production'
  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")
end

...そして出来上がり、あなたは元気です。

于 2011-03-24T00:33:19.420 に答える
3

わかりました。私はHerokuとコンパスの大ファンなので、これを何度も経験しています。

Herokuのドキュメントは、正しい情報を提供しているものの、この場合は不十分なアドバイスを提供します。

コンパスを使用する場合、最善の方法は、99.999%の確率で本番モードでコンパスをオフにすることです。

これは、開発マシンでスタイルシートをコンパイルし、herokuにプッシュする前にそれらをgitリポジトリに追加することを意味します。

コンパスをサーバー上でコンパイルできるようにすると、かなり大きなパフォーマンスの低下が発生します。

だからこれが私がすることです:

アプリのベースにconfig.ruファイルが必要です。それを開き、以下を追加します。

require 'sass/plugin/rack'
use Sass::Plugin::Rack
Sass::Plugin.options[:never_update] = true

次に、初期化子からかなりの量のコードを削除できます(特に、Sass :: Plugin :: Rackをアンロードする部分)。さらに、configフォルダーのcompass.rbからifステートメントを削除する必要があります

考えてみてください。なぜSassにサーバー上でスタイルシートをコンパイルさせたいのでしょうか。処理能力を消費するだけです。お役に立てれば、

compass watch編集::PS-スタイルシートを開発環境でコンパイルするには、コマンドラインから実行する必要があることを追加する必要があります

于 2011-03-24T00:47:18.540 に答える
0

推奨されるHeroku構成はローカルでも機能します。

  1. 2番目の「Compass::AppIntegration :: Rails.initialize!」を削除しました config / initializers / compass.rbから、必要なのは1回だけです。
  2. scssファイルが「app/views/stylesheets」にあることを確認してください

ローカルサーバーと本番サーバーの両方で、スタイルシートはtmp / stylesheetsにコンパイルされ、/stylesheetsへのリクエストはtmp/stylesheestに解決されます。2つの別々の構成は必要ありません。

于 2011-03-29T08:57:03.263 に答える