Module: AUStateSelect::InstanceTag

Defined in:
lib/au_state_select/instance_tag.rb

Instance Method Summary collapse

Instance Method Details

#state_select(priority_states, options, html_options) ⇒ Object

Adapted from Rails country_select. Just uses country codes instead of full names.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/au_state_select/instance_tag.rb', line 13

def state_select(priority_states, options, html_options)
  selected = object.send(@method_name) if object.respond_to?(@method_name)

  countries = ""

  if options.present? and (options[:include_blank] or (options[:prompt] and !selected))
    option = options[:include_blank] == true ? "" : options[:include_blank]
    countries += "<option>#{option}</option>\n"
  end

  if priority_states
    countries += options_for_select(priority_states, selected)
    countries += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
  end
  p selected
  countries = countries + options_for_select([['Australian Capital Territory', 'ACT'],['New South Wales', 'NSW'],['Northern Territory', 'NT'],['Queensland', 'QLD'],['South Australia', 'SA'],['Tasmania', 'TAS'],['Victoria', 'VIC'],['Western Australia', 'WA']], selected)

  html_options = html_options.stringify_keys
  add_default_name_and_id(html_options)

  (:select, countries.html_safe, html_options)
end

#to_state_select_tag(priority_states, html_options = {}, options = {}) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/au_state_select/instance_tag.rb', line 4

def to_state_select_tag(priority_states, html_options = {}, options = {})
  # Rails 4 stores options sent when creating an InstanceTag.
  # Let's use them!
  options = @options if defined?(@options)

  state_select(priority_states, options, html_options)
end