Rails console tips, tricks and customizations

穿精又带淫゛_ 提交于 2019-12-23 08:08:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!