Hi is it possible to manually add an option to collection_select
I have the following code and want to add "Add Customer" to the bottom
of the options list.
Hi is it possible to manually add an option to collection_select
I have the following code and want to add "Add Customer" to the bottom
of the options list.
Hi is it possible to manually add an option to collection_select
I have the following code and want to add "Add Customer" to the bottom
of the options list.
I can see that it is an array and I've looked at the documentation and
have tried a few ways of getting it to work but have failed miserably
can you give me an example of how I would add an option manually this is
what I have for the select
@customers = Customer.find(:all, :select => "id, company")
=> [#<Customer id: 6, company: "Ernie's Bakery">, #<Customer id: 7,
company: "Young's the Bakers">, #<Customer id: 8, company: "Suggs
Newsagents">]
You probably want to get a little lower-level than collection_select,
which is designed to simplify creating your select tag from a
collection of objects. Since you're adding an option to that
collection, you should go with either select_tag, or select, adding
options_for_select( Customer.find(:all).map{|c|[c.id,c.company} +
['add_a_customer', 'Add Customer'])
as the "options" parameter.
Take a look at the API for the usage of "select" or "select_tag". Also
depends on whether you're using a form helper.