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 -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -