aboutsummaryrefslogtreecommitdiffstats
path: root/app/helpers/search_helper.rb
blob: be70d974d7754244ca204e8bb3b5a257e7bd8974 (plain)
1
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
module SearchHelper

  def link_with_search(name, search, html_options = {})
    is_current = (@q and search.all? { |k,v| @q.send(k) == v })
    if is_current
      html_options[:class] = [html_options[:class], "current"].compact.join(" ")
    end
    link_to name, params.deep_merge("q" => search,:page => 1), html_options
  end

  def filter_item_class q, key
    active = false
    if q.present? && q[key].present?
      val = q[key]
      if val.is_a?(Array)
        active = val.any? &:present?
      elsif val.is_a?(Hash)
        active = val.values.any? &:present?
      else
        active = true
      end
    end
    active ? 'active' : 'inactive'
  end

end