Search code examples
ruby-on-railsselectattributesreturnrender

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.


Solution

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