【发布时间】:2020-10-04 01:25:53
【问题描述】:
我有一个包含 full_name, email, phone, address, city, state, zip 列的用户表
我需要从包含此格式的全名和电子邮件的用户表中创建一个数组 ["user1.full_name, user1.email", "user2.full_name, user2.email" 等]
我在编写此查询时遇到问题。
这是我目前所拥有的
#create empty arrays
full_names = []
emails = []
#populate the full_names array
user_full_name = User.all
user_full_name.each{|x| full_names<<x.full_name}
#populate the emails array
user_email = User.all
user_email.each{|x| emails<<x.email}
#combine the two arrays
full_names.zip(emails)
但这给了我一个多维数组 [["full_name, email"], ["full_name, email"] 等]
我如何得到它的格式 [“全名,电子邮件”,“全名,电子邮件”等]
【问题讨论】:
标签: ruby-on-rails ruby activerecord