I just stumbled over a weird problem, and I don t really understand what is causing this.
In our rails app, let s have a mixin Mixin
:
module Mixin
def foo
with_scope :find => ... do
...
end
end
end
which is include
ed into a model class elsewhere:
class Model < ActiveRecord::Base
include Mixin
...
end
calling Model.new.foo
results in an error: NoMethodError: undefined method with_scope
I then changed the foo
method to:
def foo
self.class.with_scope :find => ... do
...
end
end
But this also results in an error: NoMethodError: protected method with_scope called
This seems odd. I would have expected that the mixin methods would behave like any other method in Model
. I never stumbled over this before, because all the instance methods like save
are there and work as usual.
Am I doing it all wrong?