Module: Godmin::Helpers::Tables

Defined in:
lib/godmin/helpers/tables.rb

Instance Method Summary collapse

Instance Method Details

#column_header(attribute) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/godmin/helpers/tables.rb', line 4

def column_header(attribute)
  if @resource_class.column_names.include?(attribute.to_s)
    direction =
      if params[:order].present?
        if params[:order].match(/\A#{attribute.to_s}_(asc|desc)\z/)
          $1 == "desc" ? "asc" : "desc"
        elsif params[:order].match(/\A\w+_(asc|desc)\z/)
          $1
        end
      else
        "desc"
      end
    link_to @resource_class.human_attribute_name(attribute.to_s), url_for(params.merge(order: "#{attribute}_#{direction}"))
  else
    @resource_class.human_attribute_name(attribute.to_s)
  end
end

#column_value(resource, attribute) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/godmin/helpers/tables.rb', line 22

def column_value(resource, attribute)
  partial_override "#{controller_path}/columns/#{attribute}", resource: resource do
    column_value = resource.send(attribute)

    if column_value.is_a?(Date) || column_value.is_a?(Time)
      column_value = l(column_value, format: :long)
    end

    if column_value.is_a?(TrueClass) || column_value.is_a?(FalseClass)
      column_value = t(column_value.to_s)
    end

    column_value
  end
end