OSDN Git Service

refs #1587 レコメンド向けのTSVダウンロードをできるようにした
authorymatsumoto <ymatsumoto@appirits.com>
Sat, 4 May 2013 04:29:01 +0000 (13:29 +0900)
committerymatsumoto <ymatsumoto@appirits.com>
Sat, 4 May 2013 04:45:58 +0000 (13:45 +0900)
app/controllers/recommend_controller.rb

index dad1745..e3b5047 100644 (file)
@@ -2,8 +2,7 @@ class RecommendController < ApplicationController
   def tsv
     conditions = Product.default_condition
     @products = Product.find(:all, :conditions => flatten_conditions(conditions))
-    f = StringIO.new('', 'w')
-    CSV::Writer.generate(f,"\t","\r\n") do | writer |
+    csv_data = CSV.generate("",:col_sep => "\t",:row_sep => "\r\n") do | writer |
       writer << [:item_code, :name, :url, :stock_flg, :comment, :category, :area, :price, :img_url]
       @products.each do | product |
         columns = []
@@ -20,8 +19,6 @@ class RecommendController < ApplicationController
       end
     end
     filename = "tsv.tsv"
-    headers['Content-Type'] = "application/octet-stream; name=#{filename}"
-    headers['Content-Disposition'] = "attachment; filename=#{filename}"
-    render :text => f.string
+    send_csv(csv_data,filename)
   end
 end