I have a Rails application, and I'm trying to export data, but directly through Pry because I only need to do it once.
Is this possible with Pry? I looked at the documentation but doesn't seem like there's an easy way to dump console data anywhere.
I have a hash, with nested hashes/objects, which I need to send over to a 3rd party for work with an API. They need a dump of the data so they can set up the receiving end of my call. I'm just going to do this in Ruby now, but it would have made more sense to dump the data through PRY, rather than edit my ruby object to dump the data, which I only need once.
If you can start the server from a local command-line, or SSH to the host and run an instance there, you can use Pry for this. Basically you need to add these lines to your code at the appropriate place:
require 'pry-debugger'; binding.pry
which will stop your code and put you at the Pry prompt. At that point you can enter something like:
require 'json'
File.write('test.data', hash.to_json)
Read the Pry.debugger documentation for information about using Pry with remote Rails sessions, which might work better for you.
You can also export any string into a file (here output.txt
):
x = 'something funky'
.echo '#{x}' > output.txt
Just be careful with quotes in the string. These may lead to problems in the shell.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With