How to map more than one Attribute with ActiveRecord?

Viewed 23512

If I type in my console

u = User.first
u.friends(&map:username)

I get ["Peter", "Mary", "Jane"] but I also want to show the birthday, so how do I do that? I tried

u.friends(&map:username, &map:birthday)

but this doesn't work.

3 Answers

With ActiveRecord >= 4 you can simply use:

u.friends.pluck(:username, :birthday)
Related