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

后端 未结 10 934
悲&欢浪女
悲&欢浪女 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条回答
  •  猫巷女王i
    2021-02-02 11:32

    You can run Ruby on your Heroku instance:

    echo 'p User.first' | heroku run --no-tty 'ruby -W0 -r ./config/environment' > output.txt

    This will print the first user to the output.txt file.

    Also you can run a local script on Heroku by piping it to the stdin.

    cat my_script.rb | heroku run --no-tty 'ruby -W0 -r ./config/environment' > output.txt

    Note that it's possible that you'll get some unwanted text (like warnings) that will appear at the beginning of the output.txt file. You will have to trim it manually or by using a trimming command such as:

    tail -n +4 -f that will not print the first 4 lines.

    Here is the full example:

    cat my_script.rb | heroku run --no-tty 'ruby -W0 -r ./config/environment' | tail -n +4 -f > output.txt

提交回复
热议问题