Created
January 9, 2011 05:03
-
-
Save jimmycuadra/771433 to your computer and use it in GitHub Desktop.
Accessing a model attribute inside an ActiveRecord callback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo < ActiveRecord::Base | |
# assume Foo has an attribute called "title" | |
before_save :my_callback | |
def my_callback | |
self.title = "Prefix: #{self.title}" # this doesn't work if you remove "self" - why? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment