【发布时间】:2015-04-04 21:40:20
【问题描述】:
我正在关注 override engine models 的 Rails 指南,我正在使用 ActiveSupport::Concern 来覆盖它。
我在 seven_gallery/lib/concerns/models/gallery.rb 的引擎中创建了一个模块,其中包含以下代码:
module SevenGallery::Concerns::Models::Gallery
extend ActiveSupport::Concern
included do
has_many :photos, dependent: :destroy
default_scope { order("created_at desc") }
end
end
并将seven_gallery/app/models/seven_gallery/gallery.rb代码更改为:
module SevenGallery
class Gallery < ActiveRecord::Base
include SevenGallery::Concerns::Models::Gallery
end
end
现在在我的主机应用程序中,我已将我的引擎包含在 Gemfile by
gem "seven_gallery", path: "../seven_gallery"
我有一个 User 模型,其中包含:
class User < ActiveRecord::Base
has_one :gallery, class_name: SevenGallery::Gallery
end
但每当我运行应用程序时,我都会在 User 模型内的唯一一行上收到此错误:
uninitialized constant Concerns::Models
【问题讨论】:
-
好吧——如果对你有任何安慰的话——我“死在水里”,或多或少有同样的问题:(
-
@walt_die 我找到了解决方案。请检查答案:)
标签: ruby-on-rails ruby autoload activesupport-concern