问题
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?
回答1:
I've recently written a rails specific console tweaks blog post: https://rbjl.janlelis.com/49-railsrc-rails-console-snippets (as gist)
回答2:
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
来源:https://stackoverflow.com/questions/4774847/rails-console-tips-tricks-and-customizations