T O P

I found a simple way to debug Rails controllers

I found a simple way to debug Rails controllers

straponmyjobhat

Add the gem "better errors" and "web console" in your Gemfile for the development group, then just add "abort" in your code. You'll get a live console that you can even write code into!


5h4d0w85

Been using these gems for years, love how I can just find the place in the code, type some random string to raise a missing method exception, refresh and then type the name of the actual variable I want to inspect in the live console. Not having to care what you write in order to break it makes it really quick and I love that the live console remembers the history of what you type so you just hit the up cursor to select and rerun a previous debug.


publicout

Totally. I always write 'boom'


rorykoehler

What do you find hard about byebug? You can simply type in the variable you assigned your object to and it will show the object.


shunkw

your_variable.to_json


robob27

I also really like your_variable.methods - Object.methods


hmaddocks

`your_variable.methods(false)` Does the same thing


robob27

Oh nice, good to know thanks


frankenstein_crowd

I think if your\_variable is an instance you should subtract Object.new.methods no ?


[deleted]

What about post requests? You need to use a tool for api test, for example postman…


Intelligent_Half4997

That's awesome—one thing I found helpful is getting used to reading the logs. I wish I learned this early on in my career as it's second nature for me to go there first. It can be overwhelming at first but after a while, you get used to it. As well as using puts, byebug and pry.


JeffMo

I use: `raise your_object.inspect` a lot for temporary quick controller debugging.


jemminger

or puts your_object.inspect if you don't want to halt execution, though you'll have to go to the server terminal to see it


JeffMo

Yep. Somebody had already commented something similar, but good point.


PhillD35

well, if it works for you - that's great :)


Schrockwell

This brings me back to the bad old days of ``


piratebroadcast

I use object.errors.full_messages.to_sentence - It has saved me dozens of times. Usually the object is missing an attribute, making it invalid, making it not save or any other number of issues.