Forum: Ruby on Rails Initialization of class variables during migration

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
55f6daf7813641a0cfb30150031c48d9?d=identicon&s=25 Josh (Guest)
on 2007-05-09 20:26
(Received via mailing list)
Hi all-

Perhaps this is not a best practice, but we currently have class
variables in several class that are initialized by calls to AR
classes. For example:

   class Foo < ActiveRecord::Base
     @@my_class_var = Bar.find(:first)
   end

When using migrations to set-up a new environment, this fails as the
'bars' table does not yet exist when the environment is loaded.  Any
thoughts on how to work through this?  I imagine this is fairly
common, but like I said maybe this is not a best practice.

Thanks,
Josh
This topic is locked and can not be replied to.