What is best Rails 3 approach for mutable app-wide singleton?

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs