O'Reilly logo

Learning Rails 3 by Edd Dumbill, Simon St. Laurent, Eric J Gruber

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 18. Sending Code to the Browser: JavaScript and CoffeeScript

Rails has had a complicated and tumultuous relationship with JavaScript. It emerged at about the same time that Ajax development was making JavaScript popular again, and Rails eagerly integrated Ajax tools. Remote JavaScript (RJS) templates let developers create JavaScript with Ruby, Rails helped the Prototype library find its footing, and a variety of helper methods provided extra support in view templates.

Those solutions put Rails ahead of the crowd for a while, but developments in Rails and in the larger JavaScript world led to better conclusions. Rails’ shift toward REST-based approaches made RJS and the various helper methods seem less necessary, as code in the client could easily request XML and then JSON data from the server. Developers could cleanly separate their client and server logic that way, making it easier to maintain applications. In the JavaScript world, jQuery overtook Prototype to become the dominant JavaScript library. As JavaScript use became more complicated, many developers turned to CoffeeScript to simplify their code.

Rails 3.x has noticed and adapted to these shifts. jQuery replaced Prototype as the default framework, RJS has faded, and many helper methods were deprecated and are disappearing. Rails has also applied the same approaches demonstrated in Chapter 16 and Chapter 17 to make using CoffeeScript simple, while still allowing the use of plain old JavaScript.

Note

Perhaps not surprisingly, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required