使用关注点覆盖Rails引擎模型,得到未初始化的常量关注点:模型



我遵循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

致任何面临同样问题的人。事实证明,这是因为文档不够清晰,而且有一些缺陷。

请查看此帖子https://groups.google.com/forum/#!topic/rubyonrails docs/Oo68KwRdwyo

最新更新