Prev | Current Page 164 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"


It should also be mentioned that in all of the cases mentioned, you may assign multiple
methods, objects, or inline methods to your callbacks:
class Account < ActiveRecord::Base
before_save :setupdate, :setloggedin
private
def setupdate
self.Account_Updated = Time.now
end
def setloggedin
self.Account_LoggedIn = Time.now
end
end
CHAPTER 4 ?–  CORE FEATURES OF ACTIVE RECORD 62
Here??™s the same example using the inline method approach we outlined previously:
class Account < ActiveRecord::Base
before_save 'self.Account_Update = Time.now', 'self.Account_LoggedIn = Time.now'
end
Specific Types of Callbacks
Now that you understand what callbacks are and the basics of implementing them, let??™s look
at the 16 specific types of callbacks we can use. As we mentioned before, we all needed to
digest some code with callbacks before we really felt like we understood them, so we??™ll also
examine a working example for each.
after_find
As you would expect, the after_find method is initiated after an ActiveRecord::Base.


Pages:
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176