I always used the 'y' method to get my results cleaned up a bit in my rails console. However it doesn't seem to work anymore.
I have results to be found, and I can view the result, but just not in a clean manner. This is my rails console:
Loading development environment (Rails 3.2.6)
1.9.3-p286 :001 > y Trip.all
Trip Load (0.1ms) SELECT "trips".* FROM "trips"
NoMethodError: undefined method `y' for main:Object
from (irb):1
from /home/timen/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
from /home/timen/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
from /home/timen/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.6/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
1.9.3-p286 :002 >
It's really the first time in my life that I hear of a y method. I've always used p or pp (the latter after including 'pp') or ap (with the awesome_print gem).
It is not part of IRB, nor of pry.
It probably comes from a specific gem you had installed, so check for recent changes in your gemfile, or maybe you switched to bundler or rvm, losing some globally installed gem.
OH MY GOSH THAT'S THE EDIT
y is provided by the yaml library:
require "yaml"
Add this in some initialization script, or in your .irbrc file.
OH MY GOSH IT DOESN'T WORK!
It works in vanilla IRB, but not in rails console....
NOW THAT'S WHY
Rails console 'y' helper returns NameError rather than yaml-formatting output says that the syck YAML library was phased out in ruby 1.9.3 in favor of psych, which does not have the ymethod.
So, use awesome_print or any of its lesser brethren.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With