Module: EasyFilter::ViewHelpers
- Defined in:
- lib/easy_filter/view_helpers.rb
Overview
View helpers for EasyFilter
Instance Method Summary collapse
- #easy_filter(model_class, filters, prefixes = { main: 'filter_', from: 'from_', to: 'to_', exact: 'exact_' }) ⇒ Object
- #easy_sort(column, title = nil, sort = 'sort', direction = 'direction') ⇒ Object
Instance Method Details
#easy_filter(model_class, filters, prefixes = { main: 'filter_', from: 'from_', to: 'to_', exact: 'exact_' }) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/easy_filter/view_helpers.rb', line 16 def easy_filter(model_class, filters, prefixes = { main: 'filter_', from: 'from_', to: 'to_', exact: 'exact_' }) form = render_easy 'form_open', prefixes, model_class filters.each do |filter| f = determine_column filter, model_class form += render_field f, prefixes end form += render_easy 'buttons', prefixes form += render_easy 'form_close', prefixes end |
#easy_sort(column, title = nil, sort = 'sort', direction = 'direction') ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/easy_filter/view_helpers.rb', line 4 def easy_sort(column, title = nil, sort = 'sort', direction = 'direction') title ||= column.titleize dir = (column.to_s == params[sort] && params[direction] == 'asc') ? 'desc' : 'asc' render partial: 'easy_filter/sort_field', locals: { column: column.to_s, title: title, sort_param_name: sort, direction: dir, direction_param_name: direction } end |