Module: RailsStuff::AssociationWriter

Defined in:
lib/rails_stuff/association_writer.rb

Overview

ActiveRecord’s association can be updated with object and by object id. Owerwrite this both writers with single instruction:

association_writer :product do |val|
  super(val).tap { update_price if product }
end

Instance Method Summary collapse

Instance Method Details

#association_writer(name, &block) ⇒ Object



10
11
12
13
# File 'lib/rails_stuff/association_writer.rb', line 10

def association_writer(name, &block)
  define_method("#{name}=", &block)
  define_method("#{name}_id=", &block)
end