Module: ActiveRecord::Acts::Dropdown
- Defined in:
- lib/rails/acts_as_dropdown/acts_as_dropdown.rb
Overview
Specify this act if you want to your model be used easily with the select form helper. By default the plugin assumes you want to use the id attribute for the option’s value and the name attribute for the option’s text.
Example:
class State < ActiveRecord::Base
acts_as_dropdown
end
State.to_dropdown # => [["Alabama", 1], ["Alaska", 2], ["Arizona", 3], ["California", 4], ["Colorado", 5]]
The value, text, conditions, and order can also be altered from the default configuration by using the options hash.
Example:
class State < ActiveRecord::Base
acts_as_dropdown :text => "abbreviation", :conditions => "id < 4"
end
State.to_dropdown # => [["AL", 1], ["AK", 2], ["AZ", 3], ["CA", 4]]
The class method to_dropdown can also alter the default class configuration using the same options hash.
Example:
class State < ActiveRecord::Base
acts_as_dropdown :text => "abbreviation", :conditions => "id < 4"
end
State.to_dropdown :text => "name", :conditions => nil # => [["Alabama", 1], ["Alaska", 2], ["Arizona", 3], ["California", 4], ["Colorado", 5]]
See ActiveRecord::Acts::Dropdown::ClassMethods#acts_as_dropdown for configuration options
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Class Method Details
.included(base) ⇒ Object
:nodoc:
59 60 61 |
# File 'lib/rails/acts_as_dropdown/acts_as_dropdown.rb', line 59 def self.included(base) # :nodoc: base.extend ClassMethods end |