Alexis CHEVREUX
Alexis CHEVREUX

Reputation: 141

Rails inverse of pluck()/select()

I'm building a Rails API and I would like to know if there is a way to return the attributes of my object, but I don't want to return all of the attributes. Is there a way to prevent certain attributes from being returned? For example, I would not want to return the database IDs or the timestamps

Have a nice day.

Upvotes: 5

Views: 1972

Answers (2)

NM Pennypacker
NM Pennypacker

Reputation: 6942

How about calling the except method on your object attributes: your_object.attributes.except('id')

Upvotes: 7

Swapnil
Swapnil

Reputation: 127

Using ActiveModel::Serializer, you can specify which attributes to be added in the response of each serializer.

Refer

Upvotes: 2

Related Questions