7

There's this great post on irb tricks, but what about further customizing Rails console behavior and output?

Awesome print and Hirb are great.

SQL logging is a must for me. In your ~/.irbrc paste:

require 'logger'
ActiveRecord::Base.logger = Logger.new(STDOUT) if defined?(Rails)

What's your tip/trick/gem of choice?

Community
  • 1
  • 1
Mirko
  • 5,207
  • 2
  • 37
  • 33
  • irb link appears to have been deleted. However I think https://github.com/pry/pry has a lot to offer and probably won't evaporate anytime soon. – lacostenycoder Sep 27 '18 at 00:29

2 Answers2

1

I've recently written a rails specific console tweaks blog post: https://rbjl.janlelis.com/49-railsrc-rails-console-snippets (as gist)

J-_-L
  • 9,079
  • 2
  • 40
  • 37
0

Open last migration in your editor quickly! Assuming you already open your editor with a command like atom . to open the project root in atom, you can do:

atom $(echo "db/migrate/$(ls db/migrate | tail -1)")

Of course you can replace atom with subl etc. You can easily alias this to a function. I keep things like this in ~/.functions which load in my shell.

last_migration() {
        atom $(echo "db/migrate/$(ls db/migrate | tail -1)")
}

Then you can later create migrations and open them in 1 go:

rails g migration create_some_migration_name && last_migration
lacostenycoder
  • 10,623
  • 4
  • 31
  • 48