views:

302

answers:

2

Due to some heroku problems with rails 3 and compass framework, we followed this guide:

http://lds.li/post/673242899/compass-with-rails-3-on-heroku

and moved our stylesheets to app_name/tmp/stylesheets.

I tried using

stylesheet_link_tag "#{Rails.root}/tmp/stylesheets/main.css"

but that doesnt work as it looks for the css file in

http://localhost:3000/app_name/tmp/stylesheets/main.css

I know this is a simple fix and I'm overlooking something simple but hopefully someone can answer this with one look. Thanks in advance!

I would like to point out that we have this in our stylesheets.rb

Rails.configuration.middleware.insert_before('Rack::Sendfile', 'Rack::Static',
                                         :urls => ['/stylesheets/compiled'],
                                         :root => "#{Rails.root}/tmp")

WHen I try "compass watch" it still compiles to "tmp/stylesheets/main.css" instead of stylesheets/compiled.

+1  A: 

Change your config/compass.rb to set css_dir = "tmp/stylesheets/compiled"

Based on what you have in your configuration, you should be using this for your template:

stylesheet_link_tag "compiled/main.css"

(Which renders <link rel="/stylesheets/compiled/main.css" ...)

(The tmp dir is outside of public; it shouldn't appear in the URLs because the middleware is taking care of remapping it.)

Andrew Vit
it was originally compiled/main.css but rails keeps looking into the public/stylesheets/compiled directory instead of app_name/tmp/stylesheets. i think the middleware isn't redirecting to for me? how can i check this?
corroded
Can you clarify what you mean by "rails keeps looking"? There are two questions here: First, is the sass being compiled to tmp/stylesheets/compiled/*.css? And second, is that folder being served as /stylesheets/compiled over http, as if it were in /public?
Andrew Vit
sass is being compiled to app_root/tmp/stylesheets/compiled/*.css, and i included the stylesheet using the link_tag you said. when i look at the source of the generated page, it looks for http://localhost:3000/stylesheets/compiled/main.css, as if it was still looking at public(the changes i make to the css are in tmp, so i don't see any new styles when i refresh)
corroded
Andrew Vit
+1  A: 

I personally take a different approach to solving this problem:

Stick the following code in your compass initializer:

Sass::Plugin.options[:never_update] = true

This prevents sass from trying to write to your filesystem when the server is hit.

Just make sure that you are running compass watch in development mode and commit the compiled stylesheets to yout git repo

This saves so much time - if you don't like this approach, try hassle or one of the recent forks

stephenmurdoch
which compass initializer is this? the one in initializers or the one in config?
corroded
The easiest way is to stick it in initializers/compass.rb [**like so**](http://pastie.org/1129125) - please note that I'm using compass-0.10.5, where the initializer file has a slightly different format from previous versionss). A far better solution (and the one [advised by the guy who wrote Sass](http://nex-3.com/posts/88-sass-supports-rack)) is to leave initializers/compass.rb as it is, and put the [**following code**](http://pastie.org/1129078) into your config.ru file (the rack file at the root of your rails3 app). I think the rack approach might be better tbh but both work fine
stephenmurdoch