Adam Klein
2013-Aug-17 10:00 UTC
Feature Request for ActiveModel::Dirty - a "model_was" and a "revert_changes" methods
Hi,
I''ve encountered a need to see the model''s state before all
the changes
that were made to it.
I fantasized on something like this:
"model.was"
or
"model.before_changes"
Also, I would like to have an option to revert all changes without
reloading from DB. Something like:
"model.revert_changes"
I want to make a pull request with the following solution:
def was
result = self.dup.tap { |model| model.id <http://o.id/> = self.id }
self.changes.each {|attr, values| result[attr] = values[0]}
result
end
def revert_changes
self.changes.each {|attr, values| self[attr] = values[0]}
end
Any thoughts on the subject?
- Regards,
-- Adam Klein
--- 500tech.com
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to rubyonrails-core+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/groups/opt_out.
Adam Klein
2013-Aug-21 23:00 UTC
Re: Feature Request for ActiveModel::Dirty - a "model_was" and a "revert_changes" methods
Another option I thought about - revert_changes will return the model before the changes but without changing the object revert_changes! will revert the changes on the object itself and return it On Saturday, August 17, 2013 1:00:11 PM UTC+3, Adam Klein wrote:> > Hi, > I''ve encountered a need to see the model''s state before all the changes > that were made to it. > I fantasized on something like this: > "model.was" > or > "model.before_changes" > > Also, I would like to have an option to revert all changes without > reloading from DB. Something like: > "model.revert_changes" > > I want to make a pull request with the following solution: > def was > result = self.dup.tap { |model| model.id <http://o.id/> = self.id } > self.changes.each {|attr, values| result[attr] = values[0]} > result > end > > def revert_changes > self.changes.each {|attr, values| self[attr] = values[0]} > end > > Any thoughts on the subject? > > - Regards, > -- Adam Klein > --- 500tech.com >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out.