模型与命名空间库冲突 Class
Model Clashing With Namespaced Lib Class
在lib/events/base/event.rb
中:
module Events
module Base
class Event
并在 app/models/event.rb
中:
class Event < Show
并在 app/controllers/portal/events_controller.rb
中:
def new
@event = Event.new
在 portal/events/new
我得到这个错误:
Unable to autoload constant Event, expected /my/path/lib/events/base/event.rb to define it
因为我的库 class Events
是命名空间的,是什么导致了冲突?最简单的修复方法是什么?
我通过更改 autoload_paths
的顺序解决了这个问题,将 models
放在 lib
之前。
在lib/events/base/event.rb
中:
module Events
module Base
class Event
并在 app/models/event.rb
中:
class Event < Show
并在 app/controllers/portal/events_controller.rb
中:
def new
@event = Event.new
在 portal/events/new
我得到这个错误:
Unable to autoload constant Event, expected /my/path/lib/events/base/event.rb to define it
因为我的库 class Events
是命名空间的,是什么导致了冲突?最简单的修复方法是什么?
我通过更改 autoload_paths
的顺序解决了这个问题,将 models
放在 lib
之前。