Showing SQL statements in the Rails console

1.windows下创建_irbrc文件,并设置环境变量
2.在_irbrc文件里加入:
if ENV['RAILS_ENV']
  # Called after the irb session is initialized and Rails has been loaded
  IRB.conf[:IRB_RC] = Proc.new do
    logger = Logger.new(STDOUT)
    ActiveRecord::Base.logger = logger
    ActiveResource::Base.logger = logger
  end
end

3.
>> User.last
  User Load (0.0ms)   SELECT * FROM `users` ORDER BY users.id DESC LIMIT 1
=> #<User id: created_at: "2009-10-22 08:42:16", updated_at: "2009-10-22 08:42:16">
>>

你可能感兴趣的:(sql,windows,Ruby,Rails,ActiveRecord)