Prev | Current Page 342 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"

com", :database => "test", :username => "sa", :password => "")
mylog = Logger.new('mylog.txt')
ActiveRecord::Base.logger = mylog
temp = Account.find(1)
mylog.info("found a record with username: #{temp.username}")
CHAPTER 6 ?–  ACTIVE RECORD TESTING AND DEBUGGING 154
mylog.info("About to show comments")
temp.comments.each do |rec|
puts "#{temp.username} said #{rec.subject}"
end
mylog.info("Done showing comments")
Assuming we have some comments in our database for the given user, the following is an
example of the output displayed at the command line when we run this program:
FaliconMobileMac:~ falicon$ ruby artest.rb
Kevin said Hi.
Kevin said Good Bye
While that??™s nothing too exciting, it had an interesting side affect. Within the directory
where you ran the code, you should now see a mylog.txt file. Upon examining that file, you
should see something like the following:
[4;36;1mAccount Columns (0.069632) [0m [0;1m
SELECT
cols.COLUMN_NAME as ColName,
cols.COLUMN_DEFAULT as DefaultValue,
cols.NUMERIC_SCALE as numeric_scale,
cols.


Pages:
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354