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.
- Gartner Magic Quadrant for Application Security The market for application security testing is changing rapidly. Technology trends, such as mobile applications, advanced Web applications and dynamic languages, are forcing...
- Gartner Magic Quadrant for Mobile Application Development Platforms As unprecedented numbers of enterprises build mobile applications, the mobile application development platform market continues to grow and evolve rapidly.
- The Total Economic Impact of IBM's Worklight Platform Mobile is the fastest growing consumer technology in history. As enterprises build apps to engage these new users they are facing increased complexity...
- Four Myths of High-Productivity App Dev Debunked Debunk the main myths surrounding high-productivity application development and how both platforms have overcome them.
- LIVE EVENT: 5/7, The End of Data Protection As We Know It. Introducing a Next Generation Data Protection Architecture. Traditional backup is going away, but where does this leave end-users? All App Development White Papers | Webcasts