RJS Templates for Rails

Cody Fauser

26 September 2006

Abstract

RJS templates are an exciting and powerful new type of template added to Rails 1.1. Unlike conventional Rails templates that generate HTML or XML, RJS templates generate JavaScript code that is executed when it is returned to the browser. This JavaScript generation allows you to perform multiple page updates in-place without a page reload using Ajax. All the JavaScript you need is generated from simple templates written in Ruby. This document helps you get acquainted with how RJS templates fit into the Rails framework and gets you started with a few easy-to-follow examples.

Introduction

What Is RJS?

Ajax is a technology that allows a more desktop-like, interactive user experience to happen in the web browser. Basically, Ajax allows the browser to make remote requests in the background. These requests update the current page without reloading. Ruby on Rails has excellent support for Ajax baked right into the framework. Remote JavaScript (RJS) templates build upon the Ajax support offered by Rails 1.0, but go one step further, by allowing you to easily update multiple page elements.

RJS templates are a powerful new addition to Rails 1.1. Unlike other Rails templates, which are rendered and sent to the browser, RJS templates are used to update pages that have already been rendered.

RJS was the ...

Get RJS Templates for Rails 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.