Changing ActiveRecord attribute value in before_save hook

Posted by fifigyuri on Stack Overflow See other posts from Stack Overflow or by fifigyuri
Published on 2010-03-12T02:09:30Z Indexed on 2010/03/12 2:17 UTC
Read the original article Hit count: 692

Filed under:
|

I needed to fix the encoding of an ActiveRecord attribute and decided to do it in a before_save hook. And at this point I noticed an unexpected feature. When I wanted to change the value of the attribute, simple using the attribute_name=XY did not work as I expected. Instead of that I needed to use self[:attribute_name]=XY. So far did not recognise this behaviour and I used AR.attribute_name=XY. What is the reason for this? Does this behaviour relate to the hook or something else? Thanks for explanation.

© Stack Overflow or respective owner

Related posts about rails

Related posts about activerecord