vjnan369
vjnan369

Reputation: 853

Retrieve specified column records with attribute names

I have a model with some attributes.

If I display all records in JSON format

respond_with(Group.all)

It shows all records with corresponding attribute names. I want to display all records except some column records. So, I used

@groupDetails = Group.pluck(:id,:name,:created_at)
respond_with(@groupDetails)

It shows all specified attribute records, but I want all these records with corresponding attribute names.

Upvotes: 1

Views: 31

Answers (1)

Brad Werth
Brad Werth

Reputation: 17647

You want the select method:

Group.select(:id,:name,:created_at)

Upvotes: 1

Related Questions