Skip to content

Instantly share code, notes, and snippets.

@avidmaulanas
Created March 15, 2023 14:36
Show Gist options
  • Save avidmaulanas/372b57fe3d98614d1d99fdf35e2b8ed7 to your computer and use it in GitHub Desktop.
Save avidmaulanas/372b57fe3d98614d1d99fdf35e2b8ed7 to your computer and use it in GitHub Desktop.
make nested attributes work changes on parent save
# == Schema Information
#
# Table name: adjust_quantities
#
# quantity_in_stock :int
class AdjustQuantity
attr_accessor :adjust_quantity
def adjust_quantity=(val)
# method attribute_will_change! for trigger callbacks from parent save
attribute_will_change!(:quantity_in_stock) unless val == @adjust_quantity
@adjust_quantity = val
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment