Module: RansackFormBuilderExtensions

Defined in:
app/extensions/concerns/ransack_form_builder_extensions.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#excluding_scopes(*args) ⇒ Object



48
49
50
51
52
53
54
55
# File 'app/extensions/concerns/ransack_form_builder_extensions.rb', line 48

def excluding_scopes(*args)
  options = args.extract_options!
  scope_names = *args

  @template.(:div, class: 'excluding-scopes') do
    scope_names.map { |scope_name| scope(scope_name) }.join.html_safe
  end
end

#full_text_search(*args) ⇒ Object



31
32
33
34
35
36
37
# File 'app/extensions/concerns/ransack_form_builder_extensions.rb', line 31

def full_text_search(*args)
  options = args.extract_options!
  attribute_names = *args
  attribute_connector = '_or_'
  search_field_name = "#{attribute_names.join(attribute_connector)}_cont"
  search(search_field_name, options)
end

#locale_selectObject



39
40
41
42
43
44
45
46
# File 'app/extensions/concerns/ransack_form_builder_extensions.rb', line 39

def locale_select
  if respond_to?(:input)
    input :locale_eq, as: :select, collection: I18n.available_locales.collect { |l| [l.to_s, l.to_s] }, include_blank: true
  else
    label(:locale_eq) +  
    select(:locale_eq, I18n.available_locales.collect { |l| [l.to_s, l.to_s] }, include_blank: true)
  end
end

#scope(scope_name) ⇒ Object



57
58
59
60
61
62
63
64
# File 'app/extensions/concerns/ransack_form_builder_extensions.rb', line 57

def scope(scope_name)
  t = @template
  value = t.params.key?(:q) && t.params[:q].key?(:scopes) && t.params[:q][:scopes].key?(scope_name) && t.params[:q][:scopes][scope_name] == '1'
  t.(:label) do
    t.check_box_tag("q[scopes][#{scope_name}]", '1', value) +
      t.t("activerecord.scopes.#{scope_name}")
  end
end

#scopes(*args) ⇒ Object



66
67
68
69
70
71
# File 'app/extensions/concerns/ransack_form_builder_extensions.rb', line 66

def scopes(*args)
  options = args.extract_options!
  scope_names = *args

  scope_names.map { |scope_name| scope(scope_name) }.join.html_safe
end

#search(attribute_name, options = {}) ⇒ Object



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
28
29
# File 'app/extensions/concerns/ransack_form_builder_extensions.rb', line 3

def search(attribute_name, options = {})
  options.reverse_merge!(label_options: {}, text_field_options: {})
  autofocus = options[:autofocus]

  label_options = options.delete(:label_options)

  text_field_options = options.delete(:text_field_options)
  text_field_options.reverse_merge!(class: 'form-control', 'data-autofocus': autofocus)
  if [:last, true].include?(autofocus)
    text_field_options.reverse_merge!(autofocus: true)
  end

  @template.(:div, class: 'form-group') do
    label(attribute_name, label_options) +
      text_field(attribute_name, text_field_options)
  end

  # placeholder = true

  # if placeholder
  #   text_field_options.reverse_merge!(placeholder: true)
  #   text_field(attribute_name, text_field_options)
  # else
  #   label(attribute_name, label_options) +
  #     text_field(attribute_name, text_field_options)
  # end
end