Added hidden_attributes method for default hidden attributes. #537

Closed
wants to merge 1 commit into from

3 participants

@mkraft

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.

@steveklabnik

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

@mkraft

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

@bolshakov

We implemented same behavior in our app a bit different:

def filter(keys)
    default_keys = keys - hidden_attributes

    case
    when @only.present?
      keys & @only
    when @expose.present?
      default_keys + @expose
    else
      default_keys
    end
end
@steveklabnik

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

@mkraft

You're welcome.

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