Basically I have 3 fields in the database table and I want to return a an array to represent each row.
sqlite database resultset:
row 1)
name: John
gender: male
email: john@john.com
row 2)
name: Sarah
gender: female
email: sarah@sarah.com
Desired format from the above resultset:
[['John',male,'john@john.com'],['Sarah',female,'sarah@sarah.com']]
I've tried using User.all.map(&:name)
but that only gives me ['John','Sarah']
您将要使用map
,但是像这样:
User.all.map {|u| [u.name, u.gender, u.email]}
User.all.map {|u| [u.name, u.gender, u.email] }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.