Class: ActiveAdmin::Views::LocalizedAttributesTable

Inherits:
AttributesTable
  • Object
show all
Defined in:
lib/activeadmin-localize/attributes_table.rb

Instance Method Summary collapse

Instance Method Details

#row(*args, &block) ⇒ Object



6
7
8
9
10
11
12
13
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
# File 'lib/activeadmin-localize/attributes_table.rb', line 6

def row(*args, &block)
  _locales = ActiveAdmin::Localize.locales

  title   = args[0]
  options = args.extract_options!
  classes = [:row]
  if options[:class]
    classes << options[:class]
  elsif title.present?
    classes << "row-#{title.to_s.parameterize(separator: "_")}"
  end
  options[:class] = classes.join(' ')

  _locales.each_with_index do |locale, index|
    @table << tr(options) do
      if index == 0
        th :rowspan => _locales.length do
          header_content_for(title)
        end
      end
      @collection.each do |record|
        data = nil
        I18n.with_locale locale do
          val = record.send(title)
          data =  :div do
            (
              image_tag("activeadmin-localize/#{locale.to_s}.svg", alt: locale.to_s, title: locale.to_s, width: 20, height: 15) +
              ' ' +
              (val.blank? ? "-" : CGI.escapeHTML(val)).html_safe
            )
          end
        end
        td data
      end
    end
  end
end