【发布时间】:2016-05-17 14:36:28
【问题描述】:
注意:在您考虑将此问题标记为其他类似问题的重复之前,请注意这一点,即该问题是针对 Rails 中的问题提出的,而我搜索的其他问题涉及控制器。我没有发现任何问题,这与关注有关。
我在app/models/concerns 中有一个名为 cmets_deletion.rb 的文件,它包含以下代码:
module CommentsDeletion
extend ActiveSupport::Concern
included do
after_save :delete_comments, if: :soft_deleted?
end
def soft_deleted?
status == 'deleted'
end
def delete_comments
comments.each &:destroy
end
end
我正在尝试通过编写以下代码在我的模型中混合文件:
class Employee < ActiveRecord::Base
include CommentsDeletion
# all the other code
end
只是这样做,然后在调用 rails console 时,它给了我以下错误:
Circular dependency detected while autoloading constant Concerns::CommentsDeletion
我使用的是 Rails 4.0.2,这件事让我发疯了,我无法弄清楚我的代码有什么问题。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 models activesupport-concern