Module: RansackFormBuilderExtensions
- Defined in:
- app/extensions/concerns/ransack_form_builder_extensions.rb
Overview
:nodoc:
Instance Method Summary collapse
- #excluding_scopes(*args) ⇒ Object
- #full_text_search(*args) ⇒ Object
- #locale_select ⇒ Object
- #scope(scope_name) ⇒ Object
- #scopes(*args) ⇒ Object
- #search(attribute_name, options = {}) ⇒ Object
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) = args. scope_names = *args @template.content_tag(: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) = args. attribute_names = *args attribute_connector = '_or_' search_field_name = "#{attribute_names.join(attribute_connector)}_cont" search(search_field_name, ) end |
#locale_select ⇒ Object
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.content_tag(: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) = args. 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, = {}) .reverse_merge!(label_options: {}, text_field_options: {}) autofocus = [:autofocus] = .delete(:label_options) = .delete(:text_field_options) .reverse_merge!(class: 'form-control', 'data-autofocus': autofocus) if [:last, true].include?(autofocus) .reverse_merge!(autofocus: true) end @template.content_tag(:div, class: 'form-group') do label(attribute_name, ) + text_field(attribute_name, ) 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 |