Integrate awesome_print with Rails Console

awesome_print is code beautifying library available for beautifying Rails & Ruby code. This can be integrated with interactive Ruby and Rails console if you follow the instructions given below.

awesome_print : awesome-print-github This is available as open source on Github

Source : awesome_print

Option 1 - Integrate with Interactive Ruby

Step 1. Install

This gem can be installed with following command -

gem install awesome_print

This command will install the latest version of the gem awesome_print for you.

Step 2. Test

To test awesome_print, you need to start your Ruby environment and require awesome_print for your console,

The ap (awesome_print) command prints the result by formatting and beautifying the argument data passed to it

Step 3. Set as default for irb

You can set awesome_print formatting as default formatting for your output by putting following lines in .irbrc file.

If .irbrc file has not been created yet, then create a new one.

Open irbrc file:

vi ~/.irbrc

Paste lines:

require "awesome_print"
Step 4. Restart

Then begin new terminal session and start interactive Ruby console. This will have awesome_print as the default output formatter for you.

Option 2 - Integrate with Rails application

Step 1. Add to Gemfile

Add the awesome_print gem in the Gemfile as given below in group development (Meaning you want to use this gem only for the development environment)

group :development do
   # some other gem
   gem awesome_print

This will use gem awesome_print for your Rails application.

Step 2. Test Rails console

When you start the Rails console using

rails console

It will print output directly using the awesome_print library that you added in the group development.