Acts_as_modified Plugin

0

Sometimes when you are dealing with some of your models, you ask yourself has this model changed? if so then, which attributes? and what were their values before that change?

When should you care about these questions?

Suppose you have a model doing an expensive operation before saving. This operation is useful only if one specific attribute changed, so doing it on every save, neglecting which attributes have changed, will degrade performance significantly.

So what can you do?

You can load the model's old data from Database and check if that attribute has changed or not, and, if it has, perform your action.Or,you can use acts_as_modified plugin; it helps keeping modified attributes with their old values within a model in order to be capable of answering your questions without doing any extra database trips.

 Where can I get this from?

It depends on your Rails version:

    1. ((rails 2.1)) :Do nothing; dirty objects are already embedded in this version
    2. ((rails r7315 and above)): Install from

http://svn.viney.net.nz/things/branches/acts_as_modified_edge


    3. ((ELSE)): Install from

http://svn.viney.net.nz/things/rails/plugins/acts_as_modified

That's it; enjoy the fun!

Written By:

Osama Brekaa (http://bionuc-tech.blogspot.com/)

Post a Comment

eSpace podcast Prodcast

RSS iTunes