루비
답변
csv에 추가하면 행 또는 CSV :: Row 객체를 나타내는 배열이 필요합니다. 우선 다음과 같이 어레이를 구축하고 CSV에 그 추가 :
row = user.attributes.values_at("id", "email", "title", "first_name", "last_name", "position", "work_phone", "company", "state", "industry", "mobile", "origin", "terms")
row << events
row << roles
row << booths
csv << row
CSV#<<
말한다 :
래핑 문자열과 IO를, 행 (AN 어레이의 기본 기록 방법 또는 CSV : : 행)는 CSV로 변환되어 데이터 소스에 추가됩니다. CSV :: Row가 전달되면 행의 fields()만이 출력에 추가됩니다.
하지만 당신은 stirngs을 전달하고 있습니다. 아래 참조 :
에로 복제 시도csv << events # string
csv << roles # string
csv << booths # string
: 무슨 일이 라인 #이기
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|
ary = %w[events,roles,booths].map do |item|
user.send(item).first.name if user.send(item).present?
end
row = user.attributes.values_at("id", "email", "title", "first_name", "last_name", "position", "work_phone", "company", "state", "industry", "mobile", "origin", "terms")
row.push(*ary)
csv << row
end
end
end
Arup,하지만 두 번째, 세 번째 및 네 번째 행에 추가하는 모든 행에 대해이 행을 동일하게 입력하십시오. –
@PassionateDeveloper 오류 수정 방법에 지쳐있었습니다. –
@PassionateDeveloper 코드가 무엇인지 알려주지 않습니다. 너는하려고하고있다. –
:
과 같이 코드를 작성 : 여기
은 수정입니다 에로의? –
'csv << roles'는 값이 –
이므로 내 대답을 확인하십시오 .. –