ruby on rails - How to write this method in separate module? -



ruby on rails - How to write this method in separate module? -

right have method in specific model.

self.reflect_on_all_associations(:has_many).each |association| define_method "#{association.name}?" self.send(association.name).any? end end

i want utilize method in every model. how can write method in separate module ?

untested , memory, next should work

module reflectonassocations def included(base) base.reflect_on_all_associations(:has_many).each |association| define_method "#{association.name}?" self.send(association.name).any? end end end end

ruby-on-rails ruby

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -