0
我有一个模型类叫Person
。 人员类别具有名为car
的属性。添加关注模块到模型
现在我想在一个名为Person::Car::HasProducer
关注模型来定义模块的模块应该看起来像:
module HasProducer
def produced_by_toyota?
car == "Prius"
end
def produced_by_bmw?
car == "X3" || car == "X5"
end
end
我想找到下这个文件:顾虑/人/汽车/ has_producer.rb
在Person
-class我试图把它列入这样的:
class Person
include Person::Car::HasProducer
但我得到的错误:Unable to autoload constant Person::Car::HasProducer
我试过的modules/classes
不同的组合,但没有一个星座为我工作。
我该怎么做has_producer.rb
得到的结果是Person::Car::HasProducer
?
感谢您的评论,它的工作通过改变第一'module'为'class' 。太好了,你也注意到了'ActiveSupport :: Concern'。在这个示例代码中我省略了它。请更新您的问题,我会将其标记为正确! –
将第一个'module'更新为'class' –