【问题标题】:Overriding Rails engine model using concerns, getting uninitialized constant Concerns::Models使用关注点覆盖 Rails 引擎模型,获取未初始化的常量关注点::模型
【发布时间】: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


【解决方案1】:

致任何面临同样问题的人。原来是因为文档不够清晰,有一些缺陷。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-18
    相关资源
    最近更新 更多