Is it a) possible and b) logical to audit non-persistent (i.e. no corresponding model field) model data in rails?
I want to keep a history of some values in my rails 3 application, but currently calculate these values as attributes without corresponding database fields. Can I easily implement a persistent audit of these values without changing my models? Even if it can be done, does it make any sense?
Let's say I have a model List, which contains tasks. Each list has a boolean field (stored in the db) called complete which indicates whether the task has been completed. This is used in the model to calculate the attribute pctComplete in my List model:
def self.completedItems
tasks.whe开发者_JS百科re(:complete => true)
end
def self.pctComplete
completedItems.count / tasks.count
end
If I need to audit pctComplete, in order to provide a historical view of the data, do I need to start storing pctComplete as part of the List model before I start thinking of implementing a place to keep the audit data? If it helps, I'm planning on using a plugin such as act_as_audit to do the heavy lifting when it comes to auditing.
Thanks in advance and sorry if this question is vague or redundant.
精彩评论