ActionView::Helpers::FormOptionsHelper

collection_select

Description

collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {})


Return select and option tags for the given object and method using options_from_collection_for_select to generate the list of option tags.

Examples:
Consider you are creating a form for a new invoice in which you want a select for all the customers. In your controller you would probably get all the customers:
  1. @customers = Customer.find(:all)
In your view within the form you would than use it like:
  1. <%= collection_select('invoice', 'customer_id', @customers, 'id', 'company_name') %>
Which results in the following output:
  1. <select name="invoice[customer_id]" id="invoice_customer_id">
  2. <option value="1">Foo</option>
  3. <option value="2">Bar</option>
  4. </select>

User Contributed Notes add

Good by vinay

this is very good article....

amit from LNMIIT by amit

I got very meaningfull information.

Not good by Bo S.

Not all available parameters are listed, only one example. Too weak documentation.