Module: RecordSelect::FormBuilder

Defined in:
lib/six-updater-web/vendor/plugins/recordselect/lib/record_select/form_builder.rb

Instance Method Summary collapse

Instance Method Details

#record_select(association, options = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/six-updater-web/vendor/plugins/recordselect/lib/record_select/form_builder.rb', line 3

def record_select(association, options = {})
  reflection = @object.class.reflect_on_association(association)
  form_name = form_name_for_association(reflection)
  current = @object.send(association)
  options[:id] ||= "#{@object_name.gsub(/[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")}_#{association}"

  if [:has_one, :belongs_to].include? reflection.macro
    @template.record_select_field(form_name, current || reflection.klass.new, options)
  else
    options[:controller] ||= reflection.klass.to_s.pluralize.underscore
    @template.record_multi_select_field(form_name, current, options)
  end
end