Module: ActiveScaffold::Bridges::UsaStateSelect::UsaStateSelectOptionsHelpers

Included in:
ActionView::Helpers::Tags::UsaStateSelect
Defined in:
lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb

Constant Summary collapse

USASTATES =
[%w(Alabama AL), %w(Alaska AK), %w(Arizona AZ), %w(Arkansas AR), %w(California CA), %w(Colorado CO), %w(Connecticut CT), %w(Delaware DE), ['District of Columbia', 'DC'], %w(Florida FL), %w(Georgia GA), %w(Hawaii HI), %w(Idaho ID), %w(Illinois IL), %w(Indiana IN), %w(Iowa IA), %w(Kansas KS), %w(Kentucky KY), %w(Louisiana LA), %w(Maine ME), %w(Maryland MD), %w(Massachusetts MA), %w(Michigan MI), %w(Minnesota MN), %w(Mississippi MS), %w(Missouri MO), %w(Montana MT), %w(Nebraska NE), %w(Nevada NV), ['New Hampshire', 'NH'], ['New Jersey', 'NJ'], ['New Mexico', 'NM'], ['New York', 'NY'], ['North Carolina', 'NC'], ['North Dakota', 'ND'], %w(Ohio OH), %w(Oklahoma OK), %w(Oregon OR), %w(Pennsylvania PA), ['Rhode Island', 'RI'], ['South Carolina', 'SC'], ['South Dakota', 'SD'], %w(Tennessee TN), %w(Texas TX), %w(Utah UT), %w(Vermont VT), %w(Virginia VA), %w(Washington WA), %w(Wisconsin WI), ['West Virginia', 'WV'], %w(Wyoming WY)

Instance Method Summary collapse

Instance Method Details

#usa_state_options_for_select(selected = nil, priority_states = nil) ⇒ Object

Returns a string of option tags for the states in the United States. Supply a state name as +selected to have it marked as the selected option tag. Included also is the option to set a couple of priority_states in case you want to highligh a local area NOTE: Only the option tags are returned from this method, wrap it in a <select>



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb', line 19

def usa_state_options_for_select(selected = nil, priority_states = nil)
  if priority_states
    state_options = options_for_select(priority_states + [['-------------', '']], :selected => selected, :disabled => '')
  else
    state_options = options_for_select([])
  end

  if priority_states && priority_states.include?(selected)
    state_options += options_for_select(USASTATES - priority_states, :selected => selected)
  else
    state_options += options_for_select(USASTATES, :selected => selected)
  end

  state_options
end