Exporting CSV data from Rails

后端 未结 3 529
孤城傲影
孤城傲影 2021-01-14 10:11

I\'m working to export csv data from rails. I\'m following the tutorial here: http://railscasts.com/episodes/362-exporting-csv-and-excel?view=asciicast

In my control

3条回答
  •  粉色の甜心
    2021-01-14 10:42

    A quick version for rails console that is not for prod but just to have access to the data in excel:

    first do :

    print TableName.first.attributes.map{|a,v| a}.join(",")
    

    second do :

    TableName.all.each{|t| print t.attributes.map{|a,v| a}.join(",") + "\n"}; nil
    

    copy the result of this two call in a csv file

提交回复
热议问题