13.1. Introduction

The focus of this chapter is not on explaining JavaScript. The aim is to show you as Rails programmer how you can integrate JavaScript in a Rails application. Correspondingly, the chapters do not explain JavaScript in detail. I am assuming that you can read and understand JavaScript. If not, it may be better to skip this chapter. You can happily get by without JavaScript.

jQuery

By default, Rails 3.2 uses the jQuery Javascript library (http://jquery.com/). If you do not require this library, you should delete the following items from the file app/assets/javascripts/application.js within the asset pipeline (see Chapter 12, Asset Pipeline):
//= require jquery
//= require jquery_ujs
With jQuery, you can implement animations and Ajax interactions on your web page relatively easily.
You will find a good introduction to this topic in the jQuery documentation at http://docs.jquery.com/Main_Page.

CoffeeScript

For many Rails developers, CoffeeScript is the best thing invented since the introduction of sliced bread. CoffeeScript is a simple programming language that is converted to JavaScript via the asset pipeline. I am going to use JavaScript and CoffeeScript in this chapter. If you would like to know more about CoffeeScript, please look at the CoffeeScript documentation at http://jashkenas.github.com/coffee-script/ and as so often there is also an excellent Railscast on CoffeeScript available at http://railscasts.com/episodes/267-coffeescript-basics.

Updates about this book will be published on my Twitter feed.