Created
June 23, 2011 06:56
-
-
Save pwim/1042058 to your computer and use it in GitHub Desktop.
Rails 3.1 and after_intialize
This file contains 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 Invoice < ActiveRecord::Base | |
belongs_to :sender | |
after_initialize :assign_defaults | |
def assign_defaults | |
if new_record? && sender | |
self.fax ||= sender.fax | |
end | |
end | |
end | |
invoice = Sender.first.invoices.new # sender is nil in assign_defaults | |
invoice.sender # returns sender properly |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Same issue if I use default_value_for plugin (https://github.com/boblail/default_value_for works under 3.1). Has the ordering of after_intialize been changed in 3.1?