module ChinaRegionFu::Helpers::FormHelper
Public Instance Methods
region_select(object, methods, options = {}, html_options = {})
click to toggle source
# File lib/china_region_fu/helpers/helpers.rb, line 14 def region_select(object, methods, options = {}, html_options = {}) render_region_select_tags(object, methods, ActiveSupport::SafeBuffer.new, options, html_options) end
region_select_tag(regions, options = {})
click to toggle source
# File lib/china_region_fu/helpers/helpers.rb, line 10 def region_select_tag(regions, options = {}) render_region_select_tags(nil, regions, ActiveSupport::SafeBuffer.new, options) end
Private Instance Methods
get_choices(object, klass, region, ar_object)
click to toggle source
# File lib/china_region_fu/helpers/helpers.rb, line 42 def get_choices(object, klass, region, ar_object) return [] if object.blank? return [] if !ar_object.is_a?(ActiveRecord::Base) if %w(city city_id).include?(region.to_s) && ar_object.province_id.present? klass.where(province_id: ar_object.province_id).pluck(:name, :id) elsif %w(district district_id).include?(region.to_s) && ar_object.city_id.present? klass.where(city_id: ar_object.city_id).pluck(:name, :id) else [] end end
make_select(object, klass, region, sub_region, order_index, options = {}, html_options = {})
click to toggle source
# File lib/china_region_fu/helpers/helpers.rb, line 33 def make_select(object, klass, region, sub_region, order_index, options = {}, html_options = {}) choices = order_index == 0 ? klass.pluck(:name, :id) : get_choices(object, klass, region, options[:object]) if object select(object, region, choices, append_prompt(region, options), append_html_options(region, sub_region, html_options)) else select_tag(region, options_for_select(choices), append_html_options(region, sub_region, append_prompt(region, options))) end end