LoginSignup
2
2

More than 3 years have passed since last update.

Railsで「has been removed from the module tree but is still active!」が出た時の対処法

Last updated at Posted at 2019-08-29

たぶんこう言うnamespece内に作ったクラスを呼ぶ時にこのエラーが起きてると思う。

# app/models/some_namespace/your_model.rb

module SomeNamespace
  class YourModel
    ...
    ...
  end
end

通常これでRails側がちゃんとロードしてくれるが、developmentでrails sした状態で上のようなクラスを呼ぶファイルを更新した時にreloadが裏で走り、SomeNamespace::YourModelが無いよ的なエラーになってしまう。

解決方法

色々試してみたが、「定数読み込み順と名前空間」地獄とrequire_dependencyのやり方が一番安定してるっぽい。

# app/models/some_namespace/your_model.rb

# 最初から自分でつなげておく...
class SomeNamespace::YourModel
  ...
  ...
end

試した事

  1. SomeNamespace::YourModel::SomeNamespace::YourModelと変える(頭に::を付ける)
    これはこれで動くが全部の箇所で::を付けなければいけない
  2. development.rbでconfig.eager_load = true(全くの見当違い)
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2