Carson Reinke's Headshot

Carson Reinke's (πŸš—β˜€β˜”πŸ”‘) Blog

ActiveModel::Serialization#serializable_hash Excluding Nested Attributes

For some reason, the documentation does not go into the options available for ActiveModel::Serialization#serializable_hash. Primarily, how nested attributes can be excluded via the :include option. Each nested attributes can provide a hash of options for that object. For example, if Person has an association of projects, person.serializable_hash({:include => {:projects => {:except => [:id]}}) will exclude the id attribute of from projects. These options apply to all the Rails methods that render via serializers (e.g. respond_with, render).

ruby - rails