CoffeeScript and Rails 3.0 - Quick setupmanoj
June 23, 2011
I have been hearing a lot about CoffeeScript nowadays as you must have as well. Yes, it is built into Rails 3.1 by default. However I’m still working on a Rails 3.0 project, where I’m thinking of starting to use CoffeeScript. So, this blog post concentrates on how to quickly setup CoffeeScript into your existing Rails 3.0 project. For more details refer to the links at the bottom of this post.
Step 1: Add these to Gemfilegem 'therubyracer', :require => false
Step 2: Run Bundle Install to install coffee-script gem and other required gems
Step 3: Generate Barista initializer file config/initializers/barista_config.rb
rails generate barista:install
#Change the output root, causing Barista to compile into public/coffeescripts
Step 5: Create a folder ‘coffeescripts’ under app/ to have all your coffeescripts. All file names should end with .coffee Example: app/coffeescripts/user.coffee
/* DO NOT MODIFY. This file was compiled Thu, 23 Jun 2011 07:13:34 GMT from
Step 7: Include these coffeescript js files in your view/layouts using include tag.
And you’re done with setup. As the complied code is neat JS code, your page should continue to work fine :) Going forward you can start using CoffeeScript for writing JS code.
For deployment we can use the
barista:brew rake task in the Capistrano script using an “after” hook
References used to create above steps