Have you wasted a few hours debugging some condition only to find a query or function something was returning
One of the largest portions of time that you will spend developing an application is on debugging and optimizing. As the rails application becomes bigger with more moving parts, debugging it becomes slower and finding parts that are causing your application to be slow become fewer in between.
Rails objects can get pretty dense and hard to read when inspecting in the console. Awesome print solves this problem by prettifying the output. Read on to see by what I mean.
Lets run the command
User.first in the
rails console. This is something most of us do on a day to day basis in the rails console.
As you can see on the Terminal above, the output is kind of hard to read although the object is not that complex. Awesome print takes that output it and makes it much easier to read. Lets install the gem and see how it changes.
Use gem “awesome_print”, require:“ap”. Make sure to include do
bundle install and restart the rails console. It will not work without it.
We run the same command, however this time we just run the command by adding ap
to the beginning of the commend. So it becomes ap User.first. Basically, what you are doing is passing to the
ap method the object that you want it to print.
Rails panels adds a number of useful features to the Google Chrome inspector. To use this you will need to install the meta_request gem and also install the Chrome extension by going here.
Rails panel is something I keep switched on pretty much all the time if I’m doing any backend work. It gives you all the metrics and information required without actually having to go into the Rails console.
The first columns gives you the HTTP Response Status, the Controller and Action that your route hit, the HTTP Verb (PUT/POST/GET), request format (HTML, JSON, XML) and the response time. These metrics by itself would have been quite valuable.
I find the ActiveRecord tab to be extremely useful as it gives you the raw SQL queries being executed and the executing time for that query. It also gives you the number of queries that were used for that request which is great for optimizing the app. Apart from that, clicking on the controller name automatically opens your editor and takes you to that line of code!
The next tab is the Rendering which gives a breakdown of all the views being rendered. This is useful for finding which partials are taking the longest to render. Click on the view name automatically opens it in your editor.
Do your rails server log look like this? Filled with asset requests that you don’t really need to see, making you scroll endlessly to find the last request? My biggest annoyance would be that while scrolling I would more often than not miss the relevant request.
Quiet Assets as it names suggests removes all the asset requests from your rails console so you can see just the relevant request data. Installation is as simple as dropping
gem 'quiet_assets', group: :development into your gemfile and bundling. You should see something to the screenshot below.