Ruby on Rails Thursday, September 27, 2012

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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
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.
 
 

No comments:

Post a Comment