参数数量错误:在included do ..... end中(参数数量错误)发生了错误。

10

我正在实现一个模块,并使用 RoR 的 ActiveSupport::Concern 特性将其包含在我的类中。我在该模块中使用了 included do …… end 块,但在“included do”行上遇到了“参数错误(0 个对于 1 个)”的错误。

module Icecream
  extend ActiveSupport::Concerns

  included do  #throws error wrong no of arguments(0 for 1))
    has_many :flavours
    scope :icecreams, ->{where("has_icecreams = ?", true)}
  end
.
.
.
.
.
end

包括块(included do block)需要参数吗?


它可以不带参数工作,参见http://api.rubyonrails.org/classes/ActiveSupport/Concern.html的示例(第二个代码块)。 - Stefan
嗨 Stefan,我知道它通常可以在没有参数的情况下正常工作,不知道这次出了什么问题。 - Bloomberg
3
@ArvindMehra,正确的写法是ActiveSupport::Concern,而不是ActiveSupport::Concerns。 - nightf0x
2个回答

24

哦...终于修好了...

愚蠢的打字错误

扩展ActiveSupport::Concerns应该是Concern


4
感谢您发布解决方案,这让我避免了未来的大麻烦。 - mlkmt

16

如果您使用 include ActiveSupport::Concern 而不是 extend ActiveSupport::Concern,那么您可能会遇到相同的问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接