Suppose, I have a model
class Model < ActiveRecord::Base
has_many :other_models
end
When some other code is loaded, e.g. some plugin or extension I want to modify this relation. I try this by just reopening the class:
class Model
has_many :other_models, on_add: :method_on_add
end
But that doesn’t work. It uses only the options for the first relation. Any ideas how to accomplish this?
you can do metaprogramming; when some of your code is loaded; you can do as follow.
here is a good tutorial on metaprogrramming