Skip to main content
Tweeted twitter.com/StackCodeReview/status/774580321832534016
fixed a silly mistake since if one of the items is present then the table has to be shown
Source Link
Besi
  • 151
  • 5

In order to only show relevant information to my users I want to disable the whole panel when all fields inside that panel are empty.

Currently I do this hacky method to get to this result:

if resource.phone.present? andor
    resource.fax.present? andor 
    resource.email.present? andor 
    resource.website.present?
  panel I18n.t('contact_details') do
    attributes_table_for resource do
      row :phone if resource.phone.present?
      row :fax if resource.fax.present?
      row :email if resource.email.present?
      row :website if resource.website.present?
    end
  end
end

So I need to check all fields in order to know if I display the panel. Then once I display the panel I need to check all the fields again in order to display the given row or not.

Now the user sees only what is relevant but my admin code is cluttered and no longer as maintainable.

In order to only show relevant information to my users I want to disable the whole panel when all fields inside that panel are empty.

Currently I do this hacky method to get to this result:

if resource.phone.present? and
    resource.fax.present? and 
    resource.email.present? and 
    resource.website.present?
  panel I18n.t('contact_details') do
    attributes_table_for resource do
      row :phone if resource.phone.present?
      row :fax if resource.fax.present?
      row :email if resource.email.present?
      row :website if resource.website.present?
    end
  end
end

So I need to check all fields in order to know if I display the panel. Then once I display the panel I need to check all the fields again in order to display the given row or not.

Now the user sees only what is relevant but my admin code is cluttered and no longer as maintainable.

In order to only show relevant information to my users I want to disable the whole panel when all fields inside that panel are empty.

Currently I do this hacky method to get to this result:

if resource.phone.present? or
    resource.fax.present? or 
    resource.email.present? or 
    resource.website.present?
  panel I18n.t('contact_details') do
    attributes_table_for resource do
      row :phone if resource.phone.present?
      row :fax if resource.fax.present?
      row :email if resource.email.present?
      row :website if resource.website.present?
    end
  end
end

So I need to check all fields in order to know if I display the panel. Then once I display the panel I need to check all the fields again in order to display the given row or not.

Now the user sees only what is relevant but my admin code is cluttered and no longer as maintainable.

edited title
Link
Mast
  • 13.5k
  • 12
  • 54
  • 119

ActiveAdmin: Hide a holewhole panel in a smart way

Source Link
Besi
  • 151
  • 5

ActiveAdmin: Hide a hole panel in a smart way

In order to only show relevant information to my users I want to disable the whole panel when all fields inside that panel are empty.

Currently I do this hacky method to get to this result:

if resource.phone.present? and
    resource.fax.present? and 
    resource.email.present? and 
    resource.website.present?
  panel I18n.t('contact_details') do
    attributes_table_for resource do
      row :phone if resource.phone.present?
      row :fax if resource.fax.present?
      row :email if resource.email.present?
      row :website if resource.website.present?
    end
  end
end

So I need to check all fields in order to know if I display the panel. Then once I display the panel I need to check all the fields again in order to display the given row or not.

Now the user sees only what is relevant but my admin code is cluttered and no longer as maintainable.