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:
- @customers = Customer.find(:all)
In your view within the form you would than use it like:
- <%= collection_select('invoice', 'customer_id', @customers, 'id', 'company_name') %>
Which results in the following output:
- <select name="invoice[customer_id]" id="invoice_customer_id">
- <option value="1">Foo</option>
- <option value="2">Bar</option>
- </select>
User Contributed Notes add
- @customers = Customer.find(:all)
- <%= collection_select('invoice', 'customer_id', @customers, 'id', 'company_name') %>
- <select name="invoice[customer_id]" id="invoice_customer_id">
- <option value="1">Foo</option>
- <option value="2">Bar</option>
- </select>
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.