In my application, :foos have many :bars, and I\'m serializing each foo as JSON like so:
@foo.as_json(
except: [:created_at, :upd
I think you could try add some method like active_bars which will return exactly what you need like:
def active_bars
bars.where active: true
end
or you could even add new relation:
has_many :active_bars, -> { where active: true }, class_name: '..', foreign_id: '..'
and then you will be able write:
@foo.as_json(
except: [:created_at, :updated_at],
include: {
active_bars: { only: [:ip_addr, :active] }
}
)