I have a module Blockablethat contains associations and methods that should be included in several other classes ActiveRecord.
Relevant Code:
module Blockable
def self.included(base)
base.has_many :blocks
end
end
I want to add an extension to the association. The usual syntax (i.e. when I do not define an association in a module) looks like this:
has_many :blocks do
def method_name
... code ...
end
end
Model.first.blocks.method_name
This syntax does not work when used in a module that is included in the AR model. I get it undefined method 'method_name' for #<ActiveRecord::Relation:0xa16b714>.
Any idea how I should determine the extension of an association in a module to be included in other AR classes?
source
share