我有下面的代码:如何追加到CSV在Ruby中
def self.to_csv(options = {})
CSV.generate(options) do |csv|
csv << %w{ id email title first_name last_name position work_phone company state industry mobile origin terms events roles booths }
all.each do |user|
events = '', roles = '', booths = ''
events = user.events.first.name.to_s if user.events.present?
roles = user.roles.first.name.to_s if user.roles.present?
booths = user.booths.first.name.to_s if user.booths.present?
csv << user.attributes.values_at("id", "email", "title", "first_name", "last_name", "position", "work_phone", "company", "state", "industry", "mobile", "origin", "terms")
csv << events
csv << roles
csv << booths
end
end
end
我希望能够生成CSV和额外的列添加这些值,但我发现undefined method 'map' for "admin":String
错误。
有没有办法将这个附加到同一行上的csv?
什么是行#的错误? –
'csv << roles'因为它有一个值 –
检查我的答案.. –