Module: HotGlueHelper

Defined in:
app/helpers/hot_glue_helper.rb

Defined Under Namespace

Classes: KVObject

Instance Method Summary collapse

Instance Method Details

#enum_to_collection_select(hash) ⇒ Object



10
11
12
# File 'app/helpers/hot_glue_helper.rb', line 10

def enum_to_collection_select(hash)
  hash.collect{|k,v| KVObject.new(key: k, value: v)}
end


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/helpers/hot_glue_helper.rb', line 14

def sort_link(field, label)
  field = field.to_s
  active = params[:sort] == field
  direction = active ? params[:direction] : nil

  next_direction =
    if !active
      'asc'
    elsif direction == 'asc'
      'desc'
    else
      nil
    end

  new_params = request.query_parameters.except('sort', 'direction', 'page')
  if next_direction
    new_params['sort'] = field
    new_params['direction'] = next_direction
  end

  arrow =
    if active && direction == 'asc'
      ' ▲'
    elsif active && direction == 'desc'
      ' ▼'
    else
      ''
    end

  link_to (label + arrow).html_safe, "#{request.path}?#{new_params.to_query}".chomp('?'), style: 'white-space: nowrap', 'data-turbo-action': 'advance'
end