Sha256: 9565a848c7fc644a1717bac4efbb253df60c872ffce7837c210eb44ca20eccd5

Contents?: true

Size: 542 Bytes

Versions: 3

Compression:

Stored size: 542 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.3') 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

3 entries across 3 versions & 1 rubygems

Version Path
adva-core-0.0.6 lib/patches/rails/sti_associations.rb
adva-core-0.0.5 lib/patches/rails/sti_associations.rb
adva-core-0.0.4 lib/patches/rails/sti_associations.rb