Class: ActiveAdmin::Views::AttributesTable
- Defined in:
- lib/active_admin/views/components/attributes_table.rb
Instance Attribute Summary collapse
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #build(record, *attrs) ⇒ Object
- #content_for(attr_or_proc) ⇒ Object protected
- #content_for_attribute(attr) ⇒ Object protected
- #default_id_for_prefix ⇒ Object protected
- #empty_value ⇒ Object protected
- #header_content_for(attr) ⇒ Object protected
- #row(attr, &block) ⇒ Object
- #rows(*attrs) ⇒ Object
Instance Attribute Details
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
7 8 9 |
# File 'lib/active_admin/views/components/attributes_table.rb', line 7 def resource @resource end |
Instance Method Details
#build(record, *attrs) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/active_admin/views/components/attributes_table.rb', line 9 def build(record, *attrs) @record = record super(:for => @record) @table = table rows(*attrs) end |
#content_for(attr_or_proc) ⇒ Object (protected)
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/active_admin/views/components/attributes_table.rb', line 49 def content_for(attr_or_proc) value = case attr_or_proc when Proc attr_or_proc.call(@record) else content_for_attribute(attr_or_proc) end value = pretty_format(value) value == "" || value.nil? ? empty_value : value end |
#content_for_attribute(attr) ⇒ Object (protected)
60 61 62 63 64 65 66 |
# File 'lib/active_admin/views/components/attributes_table.rb', line 60 def content_for_attribute(attr) if attr.to_s =~ /^([\w]+)_id$/ && @record.respond_to?($1.to_sym) content_for_attribute($1) else @record.send(attr.to_sym) end end |
#default_id_for_prefix ⇒ Object (protected)
33 34 35 |
# File 'lib/active_admin/views/components/attributes_table.rb', line 33 def default_id_for_prefix 'attributes_table' end |
#empty_value ⇒ Object (protected)
45 46 47 |
# File 'lib/active_admin/views/components/attributes_table.rb', line 45 def empty_value span I18n.t('active_admin.empty'), :class => "empty" end |
#header_content_for(attr) ⇒ Object (protected)
37 38 39 40 41 42 43 |
# File 'lib/active_admin/views/components/attributes_table.rb', line 37 def header_content_for(attr) if @record.class.respond_to?(:human_attribute_name) @record.class.human_attribute_name(attr, :default => attr.to_s.titleize) else attr.to_s.titleize end end |
#row(attr, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/active_admin/views/components/attributes_table.rb', line 20 def row(attr, &block) @table << tr do th do header_content_for(attr) end td do content_for(block || attr) end end end |
#rows(*attrs) ⇒ Object
16 17 18 |
# File 'lib/active_admin/views/components/attributes_table.rb', line 16 def rows(*attrs) attrs.each {|attr| row(attr) } end |