Added hidden_attributes method for default hidden attributes. #537

wants to merge 1 commit into from

3 participants


Adds the ability to define hidden_attributes that are not rendered by default. For example, say you have a UserSerializer with a home_address attribute that you don't want to remember to exclude every time you use that serializer. Just define your serializer with hidden_attributes :home_address and then add the expose: :home_address option in the places where you do want home_address displayed.


What is the advantage of doing this, when attributes are already a white list?


It avoids defining a new class to display select attributes in exceptional cases.


We implemented same behavior in our app a bit different:

def filter(keys)
    default_keys = keys - hidden_attributes

    when @only.present?
      keys & @only
    when @expose.present?
      default_keys + @expose

This is out of date, and I'm still not convinced it's worth it. Thank you!


You're welcome.

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