5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Railsでディレクトリがロードされない場合

5
Last updated at Posted at 2015-10-04

現象

Draperを使用してDecoratorクラスで定義したメソッドを使用しようとした際に
Decoratorクラスがロードされていないために、uninitialized constantが発生。
(Railsのバージョンは4.2.1、Draperのバージョンは2.1.0)

解決策

config/application.rbに特定のディレクトリを自動ロードする設定を追加。

config/application.rb
class Application < Rails::Application

  # Decoratorディレクトリをロードする
  config.autoload_paths += Dir["#{config.root}/decorators/**/"]

end

編集後、railsを再起動させる。

5
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
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?