ruby-on-railsrubyruby-on-rails-6byebugpry-rails

How to copy multiple lines of code into byebug?


byebug doesn't seem to be able to handle multiple lines of code.

Example

I put byebug into the controller, and the next lines of code are (these could be anything, just an example here):

    payment_intent = Stripe::PaymentIntent.create({
      payment_method_types: ['card'],
      amount: @amount_minor_unit,
      currency: @currency,
      application_fee_amount: 123, # STODO
      transfer_data: {
        destination: @star.stripe_account,
      },
    })

But it does this: enter image description here

If the code is edited so it's on one single line, it succeeds:

payment_intent = Stripe::PaymentIntent.create({payment_method_types: ['card'],amount: @amount_minor_unit,currency: @currency,application_fee_amount: 123, transfer_data: {destination: @star.stripe_account,},})

But this manual editing is extremely tedious. How can I make byebug accept multiple lines of code so that I can copy/paste directly from somewhere like a controller into the byebug-halted rails server?

Other ideas

After pressing ctrl+d in the console to exit byebug, then the browser errors, then I can copy code into the browser, but the same thing happens, where it accepts the code if it's all on one line:

enter image description here

..but otherwise errors with the same syntax error as above.


Solution

  • I use the gem pry-byebug and it has the behaviour you want, you can paste multiple lines of code without it executing right away.

    https://github.com/deivid-rodriguez/pry-byebug

    You can just add it to your gem file and set break points with binding.pry