Reputation: 26192
If I wanted to get Users' name I'd do something like this
User.select(:name).find(55)
This would return :
#<User name: "Peter">
How do I get just "Peter"
.
Upvotes: 0
Views: 93
Reputation: 661
If you just want the names and you want to avoid object instanciation
User.where(id: 55).pluck(:name).first
And you will totally avoid the cost of instanciating an activeRecord object
Upvotes: 2
Reputation: 10198
Just call .name
, like so
user = User.select(:name).find(55)
user.name
Or
User.select(:name).find(55).name
Upvotes: 1