Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i map two column in single rails query

How can i map two columns in single rails query.

Eg.

 @profiles = Profile.all.map(&:user_firstname)

After running this query i would able to get users_firstname form table(which is right).

But how can i add users_firstname and users_lastname in above query.
like image 544
chaitanya Avatar asked May 04 '12 07:05

chaitanya


1 Answers

If I understood correctly, you can do:

@profiles = Profile.all.map{|p| "#{p.users_firstname} #{p.users_lastname}"}
like image 144
moritz Avatar answered Sep 20 '22 16:09

moritz