How to export a Ruby Array from my Heroku console into CSV?

后端 未结 10 911
悲&欢浪女
悲&欢浪女 2021-02-02 11:17

I am looking to export an array from my heroku console into a local CSV file.

In my current situation, I have a daily rake task which looks for tweets talking about my a

10条回答
  •  温柔的废话
    2021-02-02 11:27

    FWIW you could pretty easily puts a string with commas and newlines and then copy paste into your text editor and save as .csv, though "all of the tweets" might be a little unwieldy.

    tweets = Tweet.all
    @string = String.new()
    @string << Tweet.last.attributes.keys.join(", ") + "\n" # "header" row with attribute names
    
    
    tweets.each do |t|
      @string << t.attributes.values.join(", ") + "\n"
    end
    
    puts @string #will output string with \n newline which you could then copy paste into your editor and save as a csv
    

提交回复
热议问题