1. May

    Link to static assets on Rails 3.1

    Posted in : rails, sass, assets, and sprockets

    Having just migrated an application to Rails 3.1, we discovered that the following line is not valid anymore:

    = javascript_include_tag "rightjs", "application", :cache => "all"

    The easiest solution is moving all your javascripts in app/assets/javascripts/ then create a file all.js

    // require "rightjs"
    // require "application"

    Or we can also just add the require in application.js itself. Soon we had to do the same for our stylesheets: move them to app/assets/stylesheets.

    Also, the default path where image_tag will look for our images is now app/assets/images and no more public/images. The public folder does now shrink to only a handful of files.

    The only remaining issue should now be with images (and fonts) referenced in the stylesheets as ../images doesn’t work anymore. The first thing we tried was changing:




    Ok now it works, but is only suitable for dev because it does hit our application to serve the static files. Hopefully, Rails has a new rake task to precompile all assets to the public/assets folder:

    bundle exec rake assets:precompile RAILS_ENV=production

    Don’t forget to specify the environment otherwise the css won’t be minified properly. Also our files will be renamed from:



    application-ab5f...(more letters and digits).css

    It combines the original filename with a hash, a MD5 digest of the file content after evalutation. This is to ensure proper cache reloading - the old way with query string didn’t work with some proxies. In order to avoid serving static assets in production, we have to reference these images directly, with the hash in filename. So intead of:


    What we want is:

    url(/assets/myimage-df02(more letters and digits).png)

    Of course, doing it manually like suggested here would be tedious. The solution is to rename our stylesheet to application.css.erb (or application.css.scss.erb) and type:

    url(<%= asset_path "myimage.png" %>)

    Don’t bother trying to write:

    url(<%= asset_path "images/myimage.png" %>)

    Even if the image is actually in app/assets/images because it won’t generate the right link. We did also moved our fonts to app/assets/fonts, it works no differently that for images. Reminder: if you forgot to specify the environment (RAILS_ENV=production) when running the assets:precompile tasks the links won’t include the necessary hash in filename.


  2. Apr

    Generate checksum of file with openssl

    Posted in : openssl, chef, and checksum

    Here’s how to generate checksums of file using OpenSSL:

    # SHA256, used in chef cookbooks
    openssl dgst -sha256 path/to/myfile
    # MD5
    openssl dgst -md5 path/to/myfile


  3. Apr

    Compile Psych support in Ruby 1.9.2p180

    Posted in : rvm, ruby, 1.9.2, homebrew, and yaml

    Ruby 1.9.2 comes with a new YAML parser: Psych from Aaron Patterson (aka Tenderlove).
    But it’s compiled only if you have installed libyaml in some of ruby’s mkmf default search location.

    Here’s how to make sure ruby will compile it:

    You have homebrew installed in /usr/local:

    brew install libyaml
    rvm install ruby-1.9.2-p180

    You have homebrew installed in ~/.homebrew:

    brew install libyaml
    rvm install ruby-1.9.2-p180 -C --with-libyaml-include=$HOME/.homebrew/include,--with-libyaml-lib=$HOME/.homebrew/lib

    I tried to use the --with-libyaml-dir=$HOME/.homebrew/ shortcut, but it don’t work. So don’t loose your time.


  4. Sep

    Install Mongrel2 on Mac

    Posted in : mac, mongrel2, server, homebrew, and zeromq

    Want to play with Zed Shaw’s Mongrel2 on your mac?
    Using Homebrew in your home and not in /usr/local ?

    Here’s how to get the ØMQ Homebrew’s install picked up by Mongrel2’s Makefile:

    # install zeromq via homebrew
    > brew install zeromq
    # download and install mongrel2
    wget http://mongrel2.org/static/downloads/mongrel2-1.2.tar.bz2
    tar xvjf mongrel2-1.2.tar.bz2
    cd mongrel2-1.2
    # to install in your home
    PREFIX=$HOME OPTFLAGS="-I`brew --prefix`/include -L`brew --prefix`/lib" make all install
    # to install in the default location (/usr/local)
    sudo OPTFLAGS="-I`brew --prefix`/include -L`brew --prefix`/lib" make all install


  5. Aug


    Posted in : ruby, mongo, and benchmark

    An addition to our series of MongoDB ORM benchmarks, a brand new ruby orm for MongoDB called Mongomatic which claim to wash whiter than washing competitors.

    Mongomatic versus Mongoid

    Our benchmark highlight the fact that Mongomatic let MongoID in the dust in raw speed. I don’t know if Mongomatic is the best orms for MongoDB, but it may actually be the fastest.

    The source for all these benchmarks is freely available on github.