Skip to content

Instantly share code, notes, and snippets.

@jimmycuadra
Created January 9, 2011 05:03
Show Gist options
  • Save jimmycuadra/771433 to your computer and use it in GitHub Desktop.
Save jimmycuadra/771433 to your computer and use it in GitHub Desktop.
Accessing a model attribute inside an ActiveRecord callback
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