Module: ActiveSupport::CoreExtensions::Array::Dropdown
- Included in:
- Array
- Defined in:
- lib/rails/acts_as_dropdown/dropdown.rb
Instance Method Summary collapse
-
#to_dropdown(text = "name", value = "id") ⇒ Object
Collects the contents of the array and creates a new array that can be easily used with the
select
form helper method.
Instance Method Details
#to_dropdown(text = "name", value = "id") ⇒ Object
Collects the contents of the array and creates a new array that can be easily used with the select
form helper method.
Options
-
text
- This is the attribute that will be used as the text/label for the option tag (defaults to name). -
value
- This is the attribute that will be used to fill in the option’s value parameter (defaults to id).
Example
>> @states = State.find(:all, :order => "id")
>> @states.to_dropdown
=> [["Alabama", 1], ["Alaska", 2], ["Arizona", 3], ["California", 4], ["Colorado", 5]]
17 18 19 |
# File 'lib/rails/acts_as_dropdown/dropdown.rb', line 17 def to_dropdown(text = "name", value = "id") self.collect { |x| [x.send(text.to_sym), x.send(value.to_sym)] } end |