Using hassle gem for a happy Heroku/Sass marriage

I love Sass… there I said it. Go on tell my how much Sass sucks, I don’t care. I’ve been using it and have been in a happy code/developer relationship for quite some time now.

However there has been some hardship between Sass and I after trying to deploy my application to Heroku. The problem lies in that Heroku does not allow filesystem write access to anywhere but the temp directory. In a standard Rails application you would be putting your sass files in public/stylesheets/sass/, which would compile to public/stylesheets. This makes your app angry, APPLICATION SMASH.. ARGHHH.

So now that you have some background, have you run into this too? Yes… I thought so. Well it just so happens that I’ve got the cure for what ails you. Actually not me, more like this guy. It’s called Hassle and long story short, it is a gem/plugin that rewrites where your Sass files are compiled/served. You don’t have to do anything but install it.

Add this to your Gemfile and you’re pretty much done:

gem 'hassle'

Whoops! If you’re running a rails 3 app then you’re probably real mad at me right now. Well that’s what you get for not finishing my article. Don’t let it happen again! I forgive you.

Turns out that the straight up gem is not rails 3 ready as of yet, and totally hoses your app. Alas there is a lovely fork that provides the nurturing that I require.

gem 'hassle', :git => https://github.com/Papipo/hassle

So there you have it! Your Sass files are now written and served to/from /tmp which is a writable directory in Heroku. All of a sudden everyone is playing nice, hooray.

Just an FYI, some of the statements made in this article are fact and some are completely fabricated… believe what you will. The truth is out there.

Don’t bother with installing gems on Heroku for your non production environments with this little tidbit of knowledge.

Using Heroku for staging environments is awesome! If you don’t believe me, ask… well ask anyone. It’s free and quick to set up!

The problem I ran into is that I have an application yaml file with settings for different. This works out all great until I remembered that Heroku always deploys with rails in the production environment. Low and behold my api calls did not work because calls to the api production url is not ready.

Anyway, that is enough setup. There are a few ways to go about this… this is what I did: (using the heroku gem)

heroku config:add RACK_ENV='staging'

Fortunatley the RAILS_ENV (and MERB_ENV for those that need it) are set mirroring RACK_ENV. Heroku says that you you should not be setting RAILS_ENV, MERB_ENV directly.

Hooray! Now everything is pointing where it needs to go and we can stage away!

Working with Heroku gem and multiple environments

Quick tip:  When using the same repo on multiple Heroku apps, such as staging, qa, production, you can pass a flag to heroku gem commands so that they are specific to the environment you want.

ie: heroku logs --app staging

Just pass the —app flag along with the name of your app on heroku (in this case the name of the app would be ‘staging’)… there you go.  App specific logs.  Or whatever it is you wanted.