注:この質問を他の同様の質問と重複していると考える前に、この質問にはRailsの懸念について質問されています。私が検索した他の質問はコントローラを扱います。私が見つけた疑問は、懸念を扱っている。自動ロード中に循環依存関係が検出される問題:: <NameOfConcern>
私は内部comments_deletion.rbapp/models/concerns
という名前のファイルをしました、そして、それは次のコードが含まれます。
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を使用していますが、このことは私にはうんざりですが、私のコードに何が間違っているのか理解できません。