Yes, this is a very handy feature of ActiveRecord in Rails!
Let me summarize here some related methods that come up to my mind:
- changed? predicate if any attributes have been updated
- name_changed? described above
- name_was restores the previous value
- name_change [old_value, new_value]
- changed [list_of_changed_attributes]
- changes [hash_of_changed_attributes_with_values]
--
Thanks, Ivan Povalyukhin
On Dec 30, 7:08 am, David Kahn <d...@structuralartistry.com> wrote:
> On Thu, Dec 30, 2010 at 7:59 AM, Greg Ma <li...@ruby-forum.com> wrote:
> > Frederick Cheung wrote in post #971451:
> > > On Dec 30, 1:40pm, Greg Ma <li...@ruby-forum.com> wrote:
> > >> Hi,
> > >> Is it possible to know in a callback to know which attributes were
> > >> updated?
> > >> I want to do stuff only if one attribute has been updated.
>
> > > The changed and changes methods lists changed attributes. There are
> > > also invididual predicate methods, eg name_changed?
>
> > > Fred
>
> > Thanks I didn't know that one!
>
> Yeah me too, that's very cool, I actually have the perfect place to apply it
> today
>
>
>
>
>
>
>
>
>
> > --
> > Posted viahttp://www.ruby-forum.com/.
>
> > --
> > 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<rubyonrails-talk%2Bunsubscrib e@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/rubyonrails-talk?hl=en.
--
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.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment