Using Jammit with Capistrano and Bundler

Jammit is an awesome asset packaging library from DocumentCloud that I’ve been playing around with. It all works pretty seamlessly.

For deployment, I’m Capistrano, along with Bundler. In order to get Jammit to generate the asset files on a deploy, I added the following task to my deploy.rb file, inside of namespace :deploy

desc "Generate assets with Jammit"
task :generate_assets, :roles => :web do
  run "cd #{deploy_to}/current && bundle exec jammit"
end
after "deploy:symlink", "deploy:generate_assets"

This will automatically generate the assets during a cap deploy. bundle exec is required for running executables that comes with gems.