Created
January 26, 2011 06:39
-
-
Save ahawkins/796329 to your computer and use it in GitHub Desktop.
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
# here is a small piece of trickery to assign the remindable assoication | |
# when reminder_attributes=(attrs) is called. | |
# When using nested_attributes/build we have a problem in the reminder model | |
# since Todo.new(:reminder_attributes => {:something => :good}).reminder returns a reminder | |
# however Todo.new(:reminder_attributes => {:valid => :attributes}).reminder.remindable returns nil | |
# this alias sets the todo as the in memory object so the reminder can access the parent | |
def reminder_attributes_with_assign_todo=(reminder_attrs) | |
self.reminder_attributes_without_assign_todo = reminder_attrs.merge(:remindable => self) | |
end | |
alias_method_chain :reminder_attributes=, :assign_todo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment