Update: Check out System-wide script/console logging for something a little more convenient.
Just found this nice little nugget:
if "irb" == $0
ActiveRecord::Base.logger = Logger.new(STDOUT)
end
Chuck that into environment.rb and you’ll get log messages straight into your script/console when interacting with your models. If there was a way to tell if you were in the rails console within .irbrc you could do it system wide.
Can anybody else see a tryactiverecord.com in the making? Why_, you hear that?
Archived comments
Comments were previously allowed on articles. Though no new comments are being accepted you can see the old comments below.
-
I do something like this in my irbrc:
script_console_running = (ENV.include?('RAILS_ENV') and IRB.conf[:LOAD_MODULES].include?('console_with_helpers')) rails_running = (ENV.include?('RAILS_ENV') and !IRB.conf[:LOAD_MODULES].include?('console_with_helpers')) irb_standalone_running = (!script_console_running and !rails_running)To test it out yourself add the above and the below to your .irbrc file.
puts "script_console_running=#{script_console_running}" puts "rails_running=#{rails_running}" puts "irb_standalone_running=#{irb_standalone_running}" -
Sweet, thanks Chad! I’ve used this in my .irbrc and it works a treat.