WebFaction
Community site: login faq

There is somewhat similar but older question and the solution didn't work in my situation. http://community.webfaction.com/questions/230/installing-sass-ruby

My Django project uses django compressor python module that automatically compiles SASS stylesheet files to CSS files and does lots of other stuff like compressing JS files. The converting happens when Django renders templates. For SASS django_compressor needs command sass to be accessible via bash.

Problems arise because sass is a Ruby Gem and should be installed with gem. Webfaction has documentation about installing gems but only for Ruby on Rails.

So there's what my project needs:

  1. Install django compressor (Done, using easy install and pip)
  2. Install sass so its accessible for django compressor

I tried to install the gem by following steps in the older question and in the documentation. I have sass under /home/<username>/webapps/<app>/gems/bin/sass, but now I'm stuck.

Django gives the following error:

Caught FilterError while rendering: /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:900:in `report_activate_error': Could not find RubyGem sass (>= 0) (Gem::LoadError)
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:248:in `activate'
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:1276:in `gem'
    from /home/xeli/webapps/timu/gems/bin/sass:18

My project's wsgi file tries to include the sass directory in my projects wsgi file but I think it doesn't do much because sass is not python module.

...
sys.path = ['/home/xeli/webapps/timu/gems/bin'] + sys.path
...

I also tried to add sass to the PATH variable in ~/.bashrc

What should I do?

asked 28 Jan '12, 12:07

Akseli Palén
5614
accept rate: 50%

1

Looking at the error from Django, you may been to install the RubyGems into your /home/xeli/webapps/timu/ directory.

(28 Jan '12, 14:17) timg ♦♦

Yeah! I found the solution at last. Thanks timg for the link eventhough I had read that part before.

These are all the steps needed:

1: Install RubyGems package manager for the app.

  • Just follow the docs about Upgrading RubyGems
  • For me, this was the most difficult part to spot, because the documentation talks about Passanger-based applications. I don't have much Ruby or Rails experience so I don't even know what Passanger is. So I thought that part of docs isn't for this problem. I thought wrong.
  • More oddly the gem sass seemed to install happily eventhough RubyGems was not installed for the app. The errors began to arise not until I tried to run sass. No problems occurred when RubyGems was installed beforehand.

2: Install Sass by using gem

  • Just follow the docs about Installing Gems
  • gem install sass
  • Sass executable is now found at /home/myname/webapps/myapp/gems/bin/sass
  • Command sass is not visible for the shell (not in PATH)

3: Use absolute path to sass in Django settings.py

  • django_compressor uses a setting named COMPRESS_PRECOMPILERS
  • It enables to use special compilers for special MIME types.
  • COMPRESS_PRECOMPILERS = (('text/x-sass', '/home/myname/webapps/myapp/gems/bin/sass {infile} {outfile}'),)

4: Make sure that GEM_HOME environment variable is set when Sass is run.

  • As soon as I restarted Apache for the app and logged out, things started to go wrong. Sass couldn't find RubyGems anymore because the GEM_HOME environment variable was missing.
  • If GEM HOME is set in myproject.wsgi only Apache can use it. Because I need to run some unit tests by using manage.py test the GEM HOME should be set for them too. The solution is to set GEM HOME not in myproject.wsgi but in settings.py of the project.

Here's a code snippet from ...myapp/myproject/settings.py:


...
import os

# Add things to system path. # Gems are located at /home/myname/webapps/myapp/gems os.environ['GEM_HOME'] = '/home/myname/webapps/myapp/gems' ...

5: That's it. Hopefully :)

  • I needed to update the answer couple of times because every time I thought "that's it" a new problem occurred.
permanent link

answered 28 Jan '12, 18:03

Akseli Palén
5614
accept rate: 50%

edited 29 Jan '12, 16:08

Thank you for sharing your answer with the community.

(28 Jan '12, 18:05) johns

Little footnote: it's incredibly hard to preserve code identation and create lists with structure deeper than one level. The editor just does random things. The preview also showed that everything was fine but after save some of the identations were broken. As solution I had to remove all the identations :(

(29 Jan '12, 15:37) Akseli Palén

Yeah, I agree the Markdown editor here in OSQA isn't that great. We're a few versions behind, so perhaps this problem will be resolved when we get around to upgrading :)

In the meantime, if you need to post something with non-trivial formatting, you can use basic HTML tags in your questions, answers, and comments, eg:

  1. An ordered list...
    • with a bulleted list inside!
    • with some..
       code
          inside of it
    • and another bullet..
  2. and another list item for good measure :)
(29 Jan '12, 16:08) seanf
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×909
×4
×3
×1

question asked: 28 Jan '12, 12:07

question was seen: 9,302 times

last updated: 29 Jan '12, 16:08

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM