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

java - How to pass parameters between Request-Scoped Controllers? -

actionscript 3 - Flex: moving a point with rotation doesnt change the point XY? -

ms access - C# - Using OleDbParameter on table name -