binding.pry doesn't work (console input not available) if I start the server with the bin/dev command. It only works with bin/rails s command.
I understand it has something to do with foreman and Procfile.dev, but I don't know how.
Is this a bug or is it supposed to be like this?
With bin/dev, the Procfile.dev file is run with foreman. The pry issue is caused by the CSS and JS watchers:these just listen to changes in your CSS and JS files.
What you can do is remove the web: unset PORT && bin/rails server command from your Procfile, so it will only have the CSS and JS watchers and look like this:
js: yarn build --watch
css: yarn build:css --watch
Now you'll have to open two terminals, one with bin/rails s and the other with foreman start -f Procfile.dev. This way your pry works in the server terminal as normal and the watchers are watching as normal.
A popular approach is to use pry-remote which is useful in some ways I didn't expect: https://github.com/Mon-Ouie/pry-remote.
pry-remote opens a remote terminal, so where you drop your debugger line (binding.remote_pry in the case of pry-remote), you'll open another terminal and enter the debugging session by calling pry-remote in your shell.
I get this is a bit more complicated, I got used to it, and was able to get away from the noise logged by other process with Foreman.
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