Web Page Templates Icons, Clipart, Logos

Blog

Hot Topics

Post Archive

Tags

Aug 04, 2009 12:48 AM EDT

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

Rails Select Helper

Title:
Your Name:
Your Comment:
Please enter the text from the image in the box below:


 

 

 

 

Resource Links