Debugging Ruby on Rails Application

Komal Swami
2 min readOct 3, 2022

hello folks,

When you are learning a new language or framework, you want to see how things are working and how variables are getting populated, and why you are facing errors, exactly where things are going wrong. because of holy developers, we have some methods and gems in rails which can actually help us debug and get things sorted easily.

IRB :

IRB is your best friend when it comes to active records.IRB stands for Interactive Ruby. you can try and explore different things without actually creating a ruby file. Simply type IRB into your terminal and you are good to go. It is a type of REPL, REPL stands for read, Evaluate, Print, Loop. It is an interactive programming environment that takes a user’s input, evaluates it, and returns the result to the user.

Pry :

pry is another REPL.similar to IRB but with some additional functionalities. You have to copy and paste your ruby code on the IRB terminal to execute whereas you can directly put binding. pry after installing pry gem .this gives more flexibility for debugging your code.

Byebug :

This gem allows you to investigate your cod like a detective. you can step into your code and check your variables.

all you need to do is add byebug to your gem file bundle install.

Now you are all ready to go. add byebug into your rails controller or your ruby file. whenever you run the code control will stop where you have added the debug pointer.

Rails Logger:

If you know, You know

We have another method Rails logger similar to the console.log that of javascript. you can think of it as print statements .you can print values of different variables using this.

--

--