I have read a book entitled “The Art of Rails by Edward Benson” Published by Wiley Publishing, Inc. www.wiley.com. Its a must read book if you want to accelerate your knowledge in rails to the next level. In a certain chapter of this book covers about the five different styles of applying AJAX to enhance your web application.
These styles are by no means official standards — the terms are creations of this book — so there are no doubt more ways to organize your code. These five appear to be the predominant ones, however, so provide a good starting point for just about any application type you want to pursue.
Each of these five styles is a different way to approach AJAX, and the code you write for each will have a different look and feel to it. Which one to use is your choice, and mixing more than one style in your application is okay, too. The goal of this chapter isn’t to box you into a single way of coding but rather to make you more conscious about design issues you might otherwise have overlooked.
1. The Proxy Style
2. The Partial Style
Partial-style AJAX is a completely different way of applying AJAX made popular by the Ajax.Updater object in Prototype and the Rails macros that use it. In this style of coding, AJAX is used to transfer bits of preformed HTML, rather than data, back and forth. These HTML fragments are then inserted into some location on the page, usually depending on the status of the response (success or failure).
Partial-style AJAX is attractive because of its intuitiveness and similarity to the way in which web applications worked in the pre-AJAX days. In those days, you clicked a link and received a new page. With partial-style AJAX, you click a link and receive a new page fragment. Think of the ‘‘Next 20 Items’’ link in an AJAX-powered storefront, the ‘‘Expand Thread’’ link on a discussion board with nested comments, or the ‘‘Add Item’’ button on a Todo list application. All these actions are circumstances in which the simplest way to implement them is to connect to a URL that causes the desired action to happen and then have the server respond with only the HTML necessary to furnish the response, which replaces or adds to HTML already on the page.
3. The Puppet Style
4. The Compiled-to-web style
Compiled-to-web frameworks such as GWT are a good fit for people who prefer to avoid AJAX and the web world of languages in general and who would rather take advantage of the language environment and tools available at some higher level. For GWT, this means that developers get to write web applications as though they were Java applications, providing all the benefits of Java debugging and Java IDEs for free.
5. In-Place Application Style
This type of development is appropriate for developers who want to go after either the traditionally non-web market or court users who are concerned about poor or only periodic network connectivity. An example of the latter case is Apple’s iPhone, released in 2007 with the web as its development platform but whose slow and sometimes unavailable wireless network interfered with making this platform a true killer application. Developers quickly found ways to embed data locally using strategies ranging from cookies and bookmarklets to data URLs that enabled small web applications to be loaded on the phone in such a way that they worked both on- and offline.
For the complete details of this topic. I encourage you to buy this book “The Art of Rails by Edward Benson” Published by Wiley Publishing, Inc. www.wiley.com.