lib/active_admin/views/components/table_for.rb in activeadmin-1.0.0.pre2 vs lib/active_admin/views/components/table_for.rb in activeadmin-1.0.0.pre3
- old
+ new
@@ -37,13 +37,13 @@
within @header_row do
build_table_header(col)
end
# Add a table cell for each item
- @collection.each_with_index do |item, i|
- within @tbody.children[i] do
- build_table_cell col, item
+ @collection.each_with_index do |resource, index|
+ within @tbody.children[index] do
+ build_table_cell col, resource
end
end
end
def sortable?
@@ -94,37 +94,18 @@
tr(class: classes.flatten.join(' '), id: dom_id_for(elem))
end
end
end
- def build_table_cell(col, item)
+ def build_table_cell(col, resource)
td class: col.html_class do
- render_data col.data, item
+ html = format_attribute(resource, col.data)
+ # Don't add the same Arbre twice, while still allowing format_attribute to call status_tag
+ current_arbre_element << html unless current_arbre_element.children.include? html
end
end
- def render_data(data, item)
- value = if data.is_a? Proc
- data.call item
- elsif item.respond_to? data
- item.public_send data
- elsif item.respond_to? :[]
- item[data]
- end
- value = pretty_format(value) if data.is_a?(Symbol)
- value = status_tag value if is_boolean? data, item
- value
- end
-
- def is_boolean?(data, item)
- if item.respond_to? :has_attribute?
- item.has_attribute?(data) &&
- item.column_for_attribute(data) &&
- item.column_for_attribute(data).type == :boolean
- end
- end
-
# Returns an array for the current sort order
# current_sort[0] #=> sort_key
# current_sort[1] #=> asc | desc
def current_sort
@current_sort ||= begin
@@ -164,10 +145,10 @@
@title = args[0]
html_classes = [:col]
if @options.has_key?(:class)
html_classes << @options.delete(:class)
elsif @title.present?
- html_classes << "col-#{@title.to_s.parameterize('_')}"
+ html_classes << "col-#{ActiveAdmin::Dependency.rails.parameterize(@title.to_s)}"
end
@html_class = html_classes.join(' ')
@data = args[1] || args[0]
@data = block if block
@resource_class = args[2]