Module: AUStateSelect::InstanceTag
- Defined in:
- lib/au_state_select/instance_tag.rb
Instance Method Summary collapse
-
#state_select(priority_states, options, html_options) ⇒ Object
Adapted from Rails country_select.
- #to_state_select_tag(priority_states, html_options = {}, options = {}) ⇒ Object
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 35 36 37 |
# File 'lib/au_state_select/instance_tag.rb', line 13 def state_select(priority_states, , ) selected = object.send(@method_name) if object.respond_to?(@method_name) states = "" if .present? and ([:include_blank] or ([:prompt] and !selected)) if [:include_blank].present? option = [:include_blank] == true ? "" : [:include_blank] elsif [:prompt].present? option = [:prompt] == true ? "Please Select" : [:prompt] end states += "<option>#{option}</option>\n" end if priority_states states += (priority_states, selected) states += "<option value=\"\" disabled=\"disabled\">-------------</option>\n" end states = states + ([['Australian Capital Territory', 'ACT'],['New South Wales', 'NSW'],['Northern Territory', 'NT'],['Queensland', 'QLD'],['South Australia', 'SA'],['Tasmania', 'TAS'],['Victoria', 'VIC'],['Western Australia', 'WA']], selected) = .stringify_keys add_default_name_and_id() content_tag(:select, states.html_safe, ) 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, = {}, = {}) # Rails 4 stores options sent when creating an InstanceTag. # Let's use them! = if defined?() state_select(priority_states, , ) end |