Sha256: e11cfeaef9f7ac12c5739ce28aaf807f1ddf2eecf6f11680c04bcdfdc7c0bf9f

Contents?: true

Size: 541 Bytes

Versions: 2

Compression:

Stored size: 541 Bytes

Contents

require 'gem_patching'

# Make build associations have their given type
# i.e.: site.sections.build(:type => 'Page').class == Page
# http://pragmatig.com/2010/06/04/fixing-rails-nested-attributes-on-collections-with-sti

Gem.patching('rails', '3.0.0') do
  class ActiveRecord::Reflection::AssociationReflection
    def build_association(*options)
      if options.first.is_a?(Hash) && options.first[:type].present?
        options.first[:type].to_s.constantize.new(*options)
      else
        klass.new(*options)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
adva-core-0.0.2 lib/patches/rails/sti_associations.rb
adva-core-0.0.1 lib/patches/rails/sti_associations.rb