我正在遵循 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
其中
gem "seven_gallery", path: "../seven_gallery"
我有一个User
模型,其中包含:
class User < ActiveRecord::Base
has_one :gallery, class_name: SevenGallery::Gallery
end
但是每当我运行应用程序时,我都会在User
模型内的唯一一行上得到这个错误:
uninitialized constant Concerns::Models