我目前正在使用此代码:
CSV.open "application.csv", "a+" do |csv|
csv << [ "#{params[:first_name]}", "#{params[:last_name]}","#{params[:company]}","#{params[:email]}", "#{params[:phone]}", "#{params[:business]}", "#{params[:services]}", "#{params[:employees]}", "#{params[:turnover]}" ]
end
每次向csv写一个额外的行,我可以放入什么而不是每次都会覆盖整个文件的"a+"
,所以它总是只有一行?
答案 0 :(得分:1)
您应该使用'w'
模式。顺便说一句,你为什么写"#{params[:first_name]}"
params[:first_name]
就足够了?代码应该看起来:
CSV.open 'application.csv', 'w' do |csv|
csv << [params[:first_name], params[:last_name], params[:company], params[:email], params[:phone], params[:business], params[:services], params[:employees], params[:turnover], params[:c4l_services]]
end