here’s simplified code from the model:
class Foo < AR::Base
FIRST = Foo.first.id
end
The problem is that when testing I get well known error: “Called id
for nil…”. I guess that this constant is initialized before the
fixtures are loaded.
fixtures are loaded.
The constant is initialized when the class is loaded which is indeed
before the fixtures are. Does it have to be a constant or would
class Foo < …
def self.some_function #cache the value and return it
end
end
be acceptable?
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.