开发者

Cannot access with_scope from a mixin

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 includeed 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.

A开发者_如何学Gom I doing it all wrong?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜