Module: ExportsHelper

Defined in:
app/helpers/exports_helper.rb

Instance Method Summary collapse

Instance Method Details

#filter_value_field(rexport_model, field) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/helpers/exports_helper.rb', line 2

def filter_value_field(rexport_model, field)
  filter_field = rexport_model.field_path(rexport_model.filter_column(field))
  tag_name = "export[export_filter_attributes][#{filter_field.to_s}]"
  value = @export.filter_value(filter_field)

  case field.type
  when :boolean
    select_tag(tag_name, options_for_select([nil, ['true', 1], ['false', 0]], (value.to_i unless value.nil?)), class: 'form-control')
  when :association
    association, text_method = field.method.split('.')
    select_tag(tag_name,
      ('<option value=""></option>' +
      options_from_collection_for_select(
        rexport_model.collection_from_association(association),
        :id,
        text_method,
        value.to_i
      )).html_safe,
      class: 'form-control'
    )
  when :datetime, nil
    '&nbsp;'.html_safe
  else
    text_field_tag(tag_name, value, class: 'form-control')
  end
end