# Difference between self.field and self\[:field\] in model callbacks?

**URL:** <https://www.ruby-forum.com/t/difference-between-self-field-and-self-field-in-model-callbacks/125037>\
**Category:** Rails\
**Created:** [January 4, 2008, 7:14pm UTC](https://www.ruby-forum.com/t/difference-between-self-field-and-self-field-in-model-callbacks/125037 "2008-01-04T19:14:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@ajs](https://www.ruby-forum.com/u/ajs)\
**Post date:** [January 4, 2008, 7:14pm UTC](https://www.ruby-forum.com/t/difference-between-self-field-and-self-field-in-model-callbacks/125037/1 "2008-01-04T19:14:56Z")

</div>

I have a before\_save callback that does a bit of housekeeping to the  
model data before it’s saved.

The Rails documentation often attests the use of self.field to change  
data before it’s saved, eg:

def before\_save  
self.payment\_due ||= Time.now + 30.days  
end

But in my case doing self.field=‘something’ in the before\_save doesn’t  
appear to make any difference. However it works with self[:field]  
which is the same as write\_attribute(:field,‘something’)

Can someone explain what the difference is? (And ideally how  
self.@field fits into all this, too)
