Hey,
Here’s some simple code that represents my intent to have Administration
be
a mutable app-wide singleton, that is, there’s only one Administration
object in the database and all Rails instances refer to it/update it.
class Administration
include Singleton
include Mongoid::Document
field :cash_balance, type: Float, :default => 0.0
field :cost_of_request_to_marketmaker, type: Float, :default=>0.02
def initialize()
super(Administration.last.attributes)
end
def some_method
self.update_attributes(:cash_balance=> cash_balance +
cost_of_request_to_marketmaker)
end
end
Calling Adminstration.instance.some_method does not persist changes!
What is the best way to represent my intent in Rails 3?
Thanks,
G