Why are my ActiveRecord class instance variables disappearing after the first request in development

Posted by Paul C on Stack Overflow See other posts from Stack Overflow or by Paul C
Published on 2009-08-10T19:50:41Z Indexed on 2010/05/13 4:04 UTC
Read the original article Hit count: 251

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?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about activerecord