Module: SupplejackApi::ApplicationHelper

Defined in:
app/helpers/supplejack_api/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#extract_sort_infoObject


30
31
32
33
34
35
36
37
# File 'app/helpers/supplejack_api/application_helper.rb', line 30

def extract_sort_info
  return unless params[:order].to_s =~ /^([\w\_\.]+)_(desc|asc)$/

  @sort_column = Regexp.last_match(1)
  @sort_direction = Regexp.last_match(2)

  [@sort_column, @sort_direction]
end

#flash_messagesObject


11
12
13
14
15
16
17
18
# File 'app/helpers/supplejack_api/application_helper.rb', line 11

def flash_messages
  return nil if flash.empty?

  flash.map do |type, message|
    type = :success if type.to_s == 'notice'
    (:div, message, class: "alert-box #{type} margin-top")
  end.join.html_safe
end

#sortable(klass, column) ⇒ Object


20
21
22
23
24
25
26
27
28
# File 'app/helpers/supplejack_api/application_helper.rb', line 20

def sortable(klass, column)
  path = "admin_#{klass.to_s.tableize}_path"
  sort_column, sort_direction = extract_sort_info
  direction = column == sort_column && sort_direction == 'asc' ? 'desc' : 'asc'
  css_class = column == sort_column ? "current #{sort_direction}" : nil

  label = safe_join([t("#{klass.to_s.tableize}.#{column}", default: column.titleize), (:span)])
  link_to label, send(path, order: "#{column}_#{direction}"), class: css_class
end