Search code examples
ruby-on-railsruby-on-rails-4consolepretty-printawesomeprint

Why isn't awesome_print printing out formatted output in my Rails 4.2 console?


I’m using Rails 4.2. I have this in my Gemfile …

gem 'awesome_print', '~>1.8'

This is how it appears in Gemfile.lock

awesome_print (1.8.0)

However, when I log in to the rails console, objects are not printed out in a pretty form

$ rails c
Loading development environment (Rails 4.2.10)
irb: warn: can't alias context from irb_context.
(dev)> User.last
  User Load (0.7ms)  SELECT  `users`.* FROM `users`  ORDER BY `users`.`id` DESC LIMIT 1
=> #<User id: 88836, dob: "1960-10-02", first_name: “Test”, email: “[email protected], created_at: "2021-10-01 14:11:40", updated_at: "2021-10-01 14:11:46", middle_name: nil, last_name: “Test”, active: true, nick_name: nil, …

I’m not sure what else I need to do to get a pretty printout of objects in the Rails console. I thought including the gem would take care of this for me.


Solution

  • As mentioned in comments, per the README -- https://github.com/awesome-print/awesome_print, editing ~/.irbrc by adding these lines

    require "awesome_print"
    AwesomePrint.irb!
    

    does the job for setting awesome_print to be the default for IRB (rails console).