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

Get Learning Rails 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.