Web Page Templates Icons, Clipart, Logos
We're sorry but that file doesn't exist.

Aug 03, 2009 06:48 PM

Rails Select Helper

Ruby on Rails has a bunch of built in tools to make it easy to create HTML form elements. In fact, there are so many different ones that it’s sometimes confusing to know which one to use.

Here is an example of how to build a static drop down box with the display text and the value:

Select helper:
<%= select( "controller-name", "column", { "Tools" => "T", "Reference Resources" => "Resources"}) %>

Replace controller-name with the Rails controller that you’re going to use, “column” would be the database column where you plan to store the data, and the info between the {} is the options list. For example, { “Tools” => “T” } creates: <option value=”T”>Tools</option>

Of course, you can pass in a collection or array that was generated from a database query so that the option list is dynamic.

darren

ruby on rails | helper


Comments

Name:
Website URL:
Comment:

 

 


 

Visit www.Vauntium.com for more information.

 

 

Resource Links