2011-03-22 3 views
5

현재 Heroku와 Compass를 사용하고 있습니다. Heoku 기술 자료에서이 configuration을 권장합니다. Heroku는 읽기 전용 파일 시스템을 가지고 있으므로 컴파일 된 스타일 시트는/tmp에 저장해야합니다. 이것은 Heroku에서 원격으로 잘 작동합니다. 그러나 로컬에서는/public/stylesheets (= stylesheet_link_tag 'screen.css', :media => 'screen, projection'을 통해 호출 할 때)에서 스타일 시트를 찾을 수 있습니다.Heroku에서 나침반 사용 :/tmp에서 스타일 시트를 원격 및 로컬로 사용합니다.

이 문제를 해결하기 위해 나는/public/stylesheets에서 심볼릭 링크를 ln -s tmp/stylesheets/screen.css public/stylesheets/screen.css을 사용하여 만들었으며 제대로 작동하는 것으로 보인다.

레일스의 일부 구성을 변경하여 심볼 링크를 사용하지 않고도이 문제를 해결할 수 있습니까? 나는 많은 성공없이 찌르다. 여기

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 

여기

내 설정/초기화/compass.rb입니다.

답변

5

저는 실제로 Heroku에서 호스팅되는 Rails 응용 프로그램과 Compass를 설정하려고 했으므로이 작업을 통해 나에게 변명을 해 주셔서 감사합니다. :)

대답은 간단하다 :

수정 '설정/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 

:

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 

그런 다음 '설정/초기화/compass.rb을'수정 너는 잘한다. 확인

+0

이 기능은 레일즈 3에서 작동합니까? – anka

+0

예 - 저는 Rails 3.0.5입니다. – jdc

+2

이 솔루션에서 이해할 수없는 한 가지는 환경을 기반으로 "sass_dir"을 변경하는 이유입니다. 소스 파일이 저장된 곳이 아닌가요? dev/prok/heroku에서 dev에 비해 왜 다른가? 또한 Compass :: AppIntegration :: Rails.initialize를 호출하고 있습니다. 두번. –

3

, 내가 올바른 정보를 제공하는 동안,이 경우에 가난한 조언을 제공, 자신 그래서 난이 여러 번에게 Heroku의 문서

겪은 큰 Heroku가와 나침반 팬입니다.

나침반을 사용할 때 가장 좋은 방법은 99.999 %의 시간으로 프로덕션 모드에서 꺼야합니다.

이것은 개발 시스템에서 스타일 시트를 컴파일 한 다음 heroku로 보내기 전에 git repo에 추가한다는 것을 의미합니다.

서버에서 나침반을 컴파일하도록 허용하면 상당히 큰 성능 저하가 발생합니다. 앱의 기지에서 config.ru 파일 특성을가집니다

:

그래서 여기에 내가하는 일입니다. 를 열고 다음을 추가

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

그런 다음 초기화 (당신이 말대꾸 :: 플러그인 : 랙을 언로드 특히 부분)에서 코드의 상당수를 제거 할 수 있습니다. 또한 config 폴더의 compass.rb에서 if 문을 제거하고 싶습니다.

생각해 보면, 왜 Sass가 서버에서 스타일 시트를 컴파일하기를 원하십니까? 처리 능력 만 먹습니다., 희망이 도움이

편집 : PS - 나는 당신이 당신의 dev에 환경

+0

css 파일이 서버에서 한 번만 변경되는 경우 (한 번 컴파일 할 때마다 또는 실행될 때마다?) 서버에서 컴파일하지 않는 것이 합당한 전략 인 것으로 보입니다. 어쨌든 솔루션을 구현하려고 시도했지만 (제안 해 주셔서 고맙습니다) 일반적인 충돌로 끝났습니다 (코드 E10). config.ru와 솔루션을 구현하기 위해 바꿔야 할 다른 요소들을 알려주시겠습니까? – CuriousYogurt

+0

이것은 흥미로운 아이디어입니다. 그러나 나는 최종 분석에서 그것을 가져 오는 방법을 확신하지 못합니다. 누구든지 알면 알려주세요. – CuriousYogurt

+0

이것은 우리를 위해 일했습니다. 우리는 Jammit을 사용하여 자산을 패키지화하므로 sass 컴파일을 전혀 필요로하지 않습니다. 위의 제안을 if (ENV [ 'RACK_ENV'] || 'development')! = 'development')로 싸고 config.ru에 넣습니다. –

0

권장에게 Heroku 구성 것이다 컴파일하는 스타일 시트를 얻기 위해 이제 위해 명령 줄에서 compass watch을 실행해야 함을 추가해야합니다 또한 지역에서 일합니다.

  1. 두 번째 'Compass :: AppIntegration :: Rails.initialize!' config/initializers/compass.rb에서 한 번만 필요합니다.
  2. 당신의하는 SCS 파일이 '응용 프로그램/뷰/스타일'
스타일 시트가 TMP/스타일 시트로 컴파일됩니다 로컬 및 생산 서버에서

,과에 대한 요청이/스타일 시트는 TMP/stylesheest에 해결할 수에 있는지 확인 . 별도의 두 가지 구성이 필요 없습니다.

관련 문제