我有下面的代碼:如何追加到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'因爲它有一個值 –
檢查我的答案.. –