Home arrow JavaScript arrow Dynamically Generate a Selection List in a Rails Template
JAVASCRIPT

Dynamically Generate a Selection List in a Rails Template


If you're tired of the usual ways in which AJAX generates web widgets, read this article for something new. It lets the user choose the content of the pop-up. This article is excerpted from hack 58 of the book Ajax Hacks, written by Bruce W. Perry (O'Reilly; ISBN: 0596101694). Copyright © 2007 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

Author Info:
By: O'Reilly Media
Rating: 5 stars5 stars5 stars5 stars5 stars / 3
July 31, 2008
TABLE OF CONTENTS:
  1. · Dynamically Generate a Selection List in a Rails Template
  2. · Work with Ajax and Ruby on Rails
  3. · Rendering the HTTP Response
  4. · A Little Partial Pizzazz

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Dynamically Generate a Selection List in a Rails Template
(Page 1 of 4 )

Hack 58  Generate a selection list from server-side data using Ajax and Ruby on Rails.

This hack creates aselectelement from server-side data using a Ruby on Rails application. Unlike the typical manner in which a web widget is generated in a web page, the user chooses the content for the pop-up, and then the pop-up appears out of the blue, without anything else on the page changing. The selections that the user sees in the pop-up derive from a server-side component; they are not just hard-coded JavaScript or HTML that is part of the web page.

This hack has the same behavior as some of our earlier hacks, but the path our code takes to produce its effects is quite different. A Rails application wraps all of theXMLHttpRequestmechanics behind its own methods. Figure 7-9 shows what the web page looks like. The user reaches this page by typing http://localhost:3000/hacks/ into a web browser’s location field.

We’re using the WEBrick server that comes with Ruby on Rails.


Figure 7-9.  Cop your own pop-up

The user chooses either Team or Individual from the pop-up and clicks the Show Sports button, and anotherselectlist (whose values are determined by the user’s choice in the first list) appears just above the button.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials