New Rails templates for AJAX
Those of you who are doing some heavy AJAX with Rails should check out Cody Fauser's post about the new RJS templates supported by Rails. This allows you to extract all the javascript actions that should take place (effects, insertions, changing HTML dynamically) into a single template file. The concept is a bit different for those used to current templates. The current notion for templates is to produce some XML or HTML to present to the user. These templates allow you to define methods in the controller (that are called by AJAX calls, like link_to_remote) which handle traversing your model, just like in normal actions, but instead of placing your javascript code inside the RHTML template, you place the intended AJAX effects into an RJS template with the same name as the AJAX method/action in the controller. This may sound rather complicated, but it is actually easier to handle complex interactions with AJAX. The current helper methods tended to limit you to updating a single element as a result of various callbacks in the lifecycle of the AJAX method invokation. These templates will make it easy to define all the intended AJAX effects and results into a single place. Please note that this is in Edge Rails - the trunk of the subversion repository for now, so those wanting to try this out will need to download the trunk.
About this entry
You’re currently reading “New Rails templates for AJAX,” an entry on Late to the Party by Chris
- Published:
- 7pm on 11/29/05
- Categories:
- Rails, Programming, Ruby, Web design
No Comments
Jump to comment form | comments rss | trackback uri