Why are my ActiveRecord class instance variables disappearing after the first request in development
- by Paul C
I have a class instance variable on one of my AR classes. I set its value at boot with an initializer and, after that, never touch it again except to read from it. In development mode, this value disappears after the first request to the web server. However, when running tests, using the console or running the production server this does not happen.
# The AR class
class Group < ActiveRecord::Base
class << self
attr_accessor :path
end
end
# The initializer
Group.path = File.join(RAILS_ROOT, "public", "etc")
# First request in a view
%p= Group.path #=> "/home/rails/app/public/etc"
# Second request in a view
%p= Group.path #=> nil
Is there something about development mode that nukes instance variables from classes with each request? If so, is there a way to disable this for specific variables or classes?