This article is excerpted from Ajax on Rails, copyright 2007 O'Reilly Media Inc., all rights reserved. Used with permission from O'Reilly Media Inc.
Doing vanilla Ajax without the support of any extra libraries or helpers isn't the trick it's often portrayed to be. The idea of writing more than a dozen lines of code to do the simplest possible task is off-putting. Rails provides a huge amount of power for doing complex Ajax interactions with very minimal code.
First, we need to back up a little and look at Rails' system for handing views.
If you've ever used PHP, ColdFusion, ASP, JSP, or something similar, this will be a familiar concept. Embedded Ruby (ERb) lets you mix Ruby snippets into your HTML. ERb defines a set of special tags that get interpreted as Ruby; everything else is assumed to be plain HTML and is passed through untouched. Here are the special tags:
||The most common one, this holds a Ruby expression—which is output in place of the tag.|
||Works just like the above but suppresses newline characters from the output after the tag, which allows for cleanly organized templates without extraneous whitespace in the HTML output.|
||This holds a piece of Ruby code but doesn't output anything.|
||Works just like the above but suppresses newline characters after the tag.|
||This is a Ruby comment, which is ignored and nothing is output.|
Let's look at an example.
- The Business Value of Continuous Delivery Download this whitepaper to learn more about the business value of Continuous Delivery and see why it could be a game changer for...
- Ten Factors Shaping the Future of Application Delivery Download this research report conducted by Enterprise Management Associates (EMA) to learn how those that are seeking to accelerate application delivery are leveraging...
- Adobe Creative Cloud FAQ The following are answers to common questions about Adobe® Creative Cloud™ for teams membership, purchasing, security, and storage.
- What's coming to Adobe Creative Cloud Editing and video content creation workflows are about to get easier and more exciting, with major updates coming soon to Creative Cloud, bringing...
- What should I look for in a Next Generation Firewall? SANS Provides Guidance With so many vendors claiming to have a Next Generation Firewall (NGFW), it can be difficult to tell what makes each one different....
- Why Are Customers Really Deploying an NGFW? It seems every IT Security expert is talking about the NGFW, but what are people really doing? This webcast covers 5 real-world customer... All App Development White Papers | Webcasts