Chapter 18. Sending Code to the Browser: JavaScript and CoffeeScript
Once you wake up and smell the coffee, it’s hard to go back to sleep.
Fran Drescher
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’s 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.
Note
Perhaps not surprisingly, CoffeeScript, like Sprockets and Sass, lives outside of the Rails framework independently of what ships with recent versions. You can find the original project’s page.
Sending JavaScript to the Browser
When you created the awards and students controllers ...
Get Learning Rails 5 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.