I have a class that has a class variable which is a Hash. On the first web request the hash has the correct number of elements in it, on the second web request the hash 0 elements in it. It seems that the class is being reloaded.
Here is the class that I have inside my lib directory in a file called items.rb:
class Items
@@container = []
cattr_reader :container
def self.add_item(item)
@@container << item
end
end
I then have a simple plugin that does the following in the init.rb:
Items.add_item "item1"
Items.add_item "item2"
I then have a controller like this:
class TestController < ApplicationController
def index
render :text => "#{Items.container.size}"
end
end
On the first web request "2" is being displayed which correct. On a refresh of the browser "0" is being displayed which is incorrect. I tried this in both development and production mode with the same results. If I revert back to Rails 1.1, the correct value of "2" is displayed on all web requests.
Weird.
I have all this packaged up in a test app I can send you if needed.