I am creating a metrics hash using the following:
@metrics = Hash.new
...
@metrics[:users][:year][:male] = ...
@metrics[:users][:today][:male] = ...
...
Metrics.new(:metrics => @metrics).save
and I have the following class:
class Metrics
include Mongoid::Document
include Mongoid::Timestamps
field :metrics, :type => Hash
attr_accessible :metrics
...
end
To fetch this document, I have:
@metrics = Metrics.find(params[:id])
@metrics = @metrics[:metrics]
In order to access these elements, I need to do:
@metrics['users']['year']['male']
Is there a way I can be consistent in how I access hash values but still storing data in mongo?