Prev | Current Page 323 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"

It??™s actually very rare that your code would directly raise this error
without you explicitly defining the situation and raising the error yourself. The reason is that
within the Active Record source code, the ActiveRecordError is raised only in a unique situation
of hierarchy traversal where a class for which you are attempting to find the base does not
inherit from ActiveRecord itself. Because of Ruby??™s single-class inheritance rules, this situation
is almost impossible to produce and, therefore, very uncommon.
In the following example, to easily show the details of the exception, we raise the exception
ourselves when the record with an ID of 1 has the username of "Kevin".
# program that throws a general ActiveRecordError
require 'rubygems'
require_gem 'activerecord'
ActiveRecord::Base.establish_connection(:adapter => "sqlserver",
:host => "mydbhost.com", :database => "test", :username => "sa", :password => "")
class Account < ActiveRecord::Base
end
begin
raise ActiveRecord::ActiveRecordError if Account.find(1).


Pages:
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335