module RailsStuff::AssociationWriter
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
Public Instance Methods
association_writer(name, &block)
click to toggle source
# File lib/rails_stuff/association_writer.rb, line 10 def association_writer(name, &block) define_method("#{name}=", &block) define_method("#{name}_id=", &block) end