public
Description: JavaScript Application Framework - JS library only
Home | Edit | New

Select_field_view

Creates a drop-down menu at the location of the tag:


<%= select_field_view :name,
  :options => ['Array', 'of', 'options'],
  :bind => { 'bindings' } %>

Because this is a Ruby evaluation, you can use ruby’s methods to generate arrays very quickly. “1..3” in the place of [‘Array’, ‘of’, ‘options’] turns into [1,2,3], for example.

The array can also contain pairs:


[ [1, 'one'],[2, 'two'], [3, 'three'] ]  #=> Displays as "One, two, three" 
     #=>   but holds values "1, 2, 3"

An elegant way of creating the above array would be to use Ruby’s Array#Zip:


(1..3).zip([:one, :two, :three])

Last edited by erichocean, Sun Jun 29 18:19:57 -0700 2008
Home | Edit | New
Versions: