Skip to content

Instantly share code, notes, and snippets.

@diminish7
Created April 18, 2012 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diminish7/2415658 to your computer and use it in GitHub Desktop.
Save diminish7/2415658 to your computer and use it in GitHub Desktop.
Proposed change to build_association
# Returns a new, unsaved instance of the associated class. +options+ will
# be passed to the class's constructor.
def build_association(*options, &block)
if options.first.is_a?(Hash) && (subclass_name = options.first.with_indifferent_access[klass.inheritance_column]).present?
begin
subclass = klass.module_eval { compute_type(subclass_name) }
raise NameError unless (subclass == klass || subclass.ancestors.include?(klass))
subclass.new(*options, &block)
rescue NameError
raise ActiveRecord::SubclassNotFound.new("Invalid single-table inheritance type: #{subclass_name} is not a subclass of #{klass.name}")
end
else
klass.new(*options, &block)
end
end
@diminish7
Copy link
Author

All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy.

@diminish7
Copy link
Author

More commenting ...

@diminish7
Copy link
Author

Comment comment comment blah blah blah.

@diminish7
Copy link
Author

And again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment