G-money
2012-Sep-27 14:19 UTC
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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/5pPH6VKnXScJ. For more options, visit https://groups.google.com/groups/opt_out.