Cover by Edd Dumbill, Simon St. Laurent, Eric J Gruber

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

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, ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required