Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Only show empty_value for attributes_table row if the row is actually empty #1479

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
3 participants
Contributor

jpmckinney commented Jul 6, 2012

If you do:

ActiveAdmin.register ClassName do
  show do
    attributes_table do
      row :attribute_name do |x|
        div "some content"
        if some_condition
          div "other content"
        end
      end
    end
  end
end

and if some_condition evaluates to false, then empty_value will be rendered after "some_content", even though the row is not empty! You can get around this by doing:

row :attribute_name do |x|
  div "some content"
  if some_condition
    div "other content"
  end
  "foobar"
end

because "foobar" won't be rendered, but that seems like a cludgy workaround. This pull request fixes this, so that an attributes_table row can return nil. The new code checks whether any content was created by the block passed to row, instead of checking the block's return value.

Specs included.

Contributor

jpmckinney commented Jul 6, 2012

This is a re-opening of #1460. Copying comment from that issue:

There is an error in the attributes_table_spec tests. The post ID is set to 1, the test compares it to "2" and yet the test passes. This is because the let statements need to be in the most deeply nested describe block. This sort of error can be avoided by not trying to DRY the tests too much. Removing the let statements and just writing set[0] instead of title, etc. is an alternative solution to this error in the tests.

This pull request passes (merged 89c27ff into ffef502).

@seanlinsley seanlinsley commented on the diff Mar 10, 2013

lib/active_admin/views/components/attributes_table.rb
@@ -50,7 +51,7 @@ def content_for(attr_or_proc)
content_for_attribute(attr_or_proc)
end
value = pretty_format(value)
- value == "" || value == nil ? empty_value : value
+ (value == "" || value == nil) && previous == current_arbre_element.to_s ? empty_value : value
@seanlinsley

seanlinsley Mar 10, 2013

Owner

Can't we rely on Active Support here?

value.blank? && previous == current_arbre_element.to_s ? empty_value : value
Owner

seanlinsley commented May 7, 2013

Merged in as of 600b539

@seanlinsley seanlinsley closed this May 7, 2013

@jpmckinney jpmckinney deleted the unknown repository branch Sep 29, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment