Method: ActsAs::ClassMethods#acts_as

Defined in:
lib/acts_as.rb

#acts_as(association, with: [], prefix: [], **options) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/acts_as.rb', line 36

def acts_as(association, with: [], prefix: [], **options)
  belongs_to(association, **options.merge(autosave: true))
  define_method(association) do |*args|
    acted = super(*args) || send("build_#{association}", *args)
    acted.save if persisted? && acted.new_record?
    acted
  end

  if (association_class = (options[:class_name] || association).to_s.camelcase.constantize).table_exists?
    whitelist_and_delegate_fields(association_class, association, prefix, with)
    override_method_missing
  end
end