0
format.csv { send_data @find_customer.to_csv, :filename => "customer" + ".csv" }
format.xls { send_data @find_customer.to_csv(col_sep: "\t"), filename: 'customer.xls'}
型號
def self.to_csv(options = {})
CSV.generate(options) do |csv|
csv << ["SHW#", "LeadId", "Fullname", "Address", "City", "State", "Zip", "Phone", "Email", "Created-At"]
all.each do |customer|
csv << [customer.id, customer.leadid, "#{customer.first_name} #{customer.last_name}", customer.customer_address, customer.customer_city, customer.customer_state, customer.customer_zip, customer.customer_phone, customer.email, customer.created_at.strftime("%m/%d/%Y")]
end
end
end
如何通過在to_csv方法額外的參數。我想在to_csv方法中傳遞start_date和end_date,所以我該如何?
更新1
如果我通過
format.xls {SEND_DATA @ find_customer.to_csv(col_sep: 「\ t」 的,:START_DATE => 「日期」),文件名:「顧客。 XLS'}
然後得到錯誤,如:未知的選項起始日期
那麼問題是什麼?將這些參數放入第5行的數組中。 –
給我例子,self.to_csv(options = {}),在這裏我想從控制器獲取值 –