Module: ActionView::Helpers::FormOptionsHelper
- Defined in:
- lib/us_states_select.rb
Constant Summary collapse
- US_STATES =
[["Alaska", "AK"], ["Alabama", "AL"], ["Arkansas", "AR"], ["Arizona", "AZ"], ["California", "CA"], ["Colorado", "CO"], ["Connecticut", "CT"], ["District of Columbia", "DC"], ["Delaware", "DE"], ["Florida", "FL"], ["Georgia", "GA"], ["Hawaii", "HI"], ["Iowa", "IA"], ["Idaho", "ID"], ["Illinois", "IL"], ["Indiana", "IN"], ["Kansas", "KS"], ["Kentucky", "KY"], ["Louisiana", "LA"], ["Massachusetts", "MA"], ["Maryland", "MD"], ["Maine", "ME"], ["Michigan", "MI"], ["Minnesota", "MN"], ["Missouri", "MO"], ["Mississippi", "MS"], ["Montana", "MT"], ["North Carolina", "NC"], ["North Dakota", "ND"], ["Nebraska", "NE"], ["New Hampshire", "NH"], ["New Jersey", "NJ"], ["New Mexico", "NM"], ["Nevada", "NV"], ["New York", "NY"], ["Ohio", "OH"], ["Oklahoma", "OK"], ["Oregon", "OR"], ["Pennsylvania", "PA"], ["Rhode Island", "RI"], ["South Carolina", "SC"], ["South Dakota", "SD"], ["Tennessee", "TN"], ["Texas", "TX"], ["Utah", "UT"], ["Virginia", "VA"], ["Vermont", "VT"], ["Washington", "WA"], ["Wisconsin", "WI"], ["West Virginia", "WV"], ["Wyoming", "WY"]]
Instance Method Summary collapse
- #us_state_options_for_select(selected = nil, options = {}) ⇒ Object
- #us_state_select(object, method, us_state_options = {}, options = {}, html_options = {}) ⇒ Object
Instance Method Details
#us_state_options_for_select(selected = nil, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/us_states_select.rb', line 4 def (selected = nil, = {}) = "" priority_states = lambda { |state| [:priority].include?(state.last) } [:show] = :full if [:with_abbreviation] states_label = case [:show] when :full_abb then lambda { |state| [state.first, state.last] } when :full then lambda { |state| [state.first, state.first] } when :abbreviations then lambda { |state| [state.last, state.last] } when :abb_full_abb then lambda { |state| ["#{state.last} - #{state.first}", state.last] } else lambda { |state| state } end states_label = [:show] if [:show].is_a?(Proc) if [:priority] += (US_STATES.select(&priority_states).collect(&states_label), selected) += "<option value=\"\" disabled=\"disabled\">-------------</option>\n" selected = nil if [:priority].include?(selected) end += (US_STATES.collect(&states_label), selected) end |
#us_state_select(object, method, us_state_options = {}, options = {}, html_options = {}) ⇒ Object
28 29 30 31 |
# File 'lib/us_states_select.rb', line 28 def us_state_select(object, method, = {}, = {}, = {}) .merge!() InstanceTag.new(object, method, self, .delete(:object)).to_us_state_select_tag(, ) end |