Created
May 3, 2012 21:37
-
-
Save codatory/2589714 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
| module Sanity | |
| module ActsAsSaneNestedAttributes | |
| def self.included(base) | |
| base.extend(ClassMethods) | |
| end | |
| module ClassMethods | |
| def acts_as_sane_nested_attributes(options = []) | |
| puts 'Setting up child callbacks' | |
| ActiveRecord::Callbacks::CALLBACKS.each do |callback| | |
| options.to_a.each do |child| | |
| puts "Checking if #{child} supports #{callback}" | |
| if child.to_s.classify.constantize.send(callback.to_sym).any? | |
| puts "Setting #{callback} for #{child}" | |
| self.send(callback.to_sym, "#{child.to_s.pluralize}.each{|c| c.run_callbacks(#{callback.to_sym})}") | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| ActiveRecord::Base.send :include, Sanity::ActsAsSaneNestedAttributes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment