Using Compass on Heroku: / tmp for styles remotely and locally

I am currently using Compass with Heroku, using this configuration recommended in the Heroku Knowledge Base. Heroku has a read-only file system, so compiled style sheets need to be stored in / tmp. This works great on Heroku; locally, however, Rails expects to find stylesheets in / public / stylesheets (when called through = stylesheet_link_tag 'screen.css', :media => 'screen, projection').

To solve the problem, I created symbolic links in / public / stylesheets using ln -s tmp/stylesheets/screen.css public/stylesheets/screen.cssand it seems to work.

Is there a way to solve this problem without using symbolic links, perhaps by changing some configuration in Rails? I poked without much success.

Here is my 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")

And here is my 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

.

+5
3

Compass Rails-, Heroku, , .:)

:

'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

... , .

+5

, , .

Heroku, , .

99.999% .

, , git , .

, .

, :

config.ru . :

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

( , Sass:: Plugin:: Rack). , if compass.rb

, , Sass ? . , ,

:: PS - , compass watch ,

+3

Heroku .

  • "Compass:: AppIntegration:: Rails.initialize!" config/initializers/compass.rb, .
  • , scss 'app/views/stylesheets'

tmp/stylesheets, /stylesheets tmp/stylesheest. .

0

All Articles