关注不是在 Rails 5 中加载

Max*_*Max 2 ruby ruby-on-rails heroku activesupport-concern

我有一个基本的 Rails 应用程序,我正在尝试使用对干燥模型的关注。在开发环境中一切正常,但是当我尝试将应用程序上传到 Heroku 时,它不断给我这个错误:

/app/app/models/address.rb:3:in `<class:Address>': uninitialized constant Address::Persistable (NameError)
Run Code Online (Sandbox Code Playgroud)

我试图禁用急切加载,但没有帮助。

这是我的地址模型:

class Address < ApplicationRecord

  include Persistable

  belongs_to :city
  belongs_to :company

  validates :city_id, :human, :lat, :lng, presence: true
end
Run Code Online (Sandbox Code Playgroud)

这是我命名为“persistable”的模块,位于 app/models/concerns/persistable.rb

module Persistable
  extend ActiveSupport::Concern

  included do
    scope :historical, -> { where(is_historical: true) }
    scope :deleted, -> { where(is_deleted: true) }
    default_scope { where(is_historical: false, is_deleted: false) }

    def delete
      update_attribute(:is_deleted, true)
    end

    def archive
      update_attribute(:is_historical, true)
    end

    def revive
      update_attribute(:is_historical, false)
      update_attribute(:is_deleted, false)
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

我已经做了什么:

  • 试图关闭急切加载
  • 试图将Persistable模块移出concerns目录
  • 尝试包含concerns自动加载配置的路径

没有任何效果,我仍然有这个问题!

更新

我做了命令表单指南 rails r 'puts ActiveSupport::Dependencies.autoload_paths'来检查 autoload_paths ,我得到:

D:/work/rails/www/app/models/concerns
D:/work/rails/www/app/assets
D:/work/rails/www/app/channels
D:/work/rails/www/app/controllers
D:/work/rails/www/app/helpers
D:/work/rails/www/app/jobs
D:/work/rails/www/app/mailers
D:/work/rails/www/app/models
D:/work/rails/www/test/mailers/previews
Run Code Online (Sandbox Code Playgroud)

小智 6

我有相同的错误消息的类似问题,但不同的修复。

跑步spring stop为我解决了它。

当 rails 无法自动加载时,重置弹簧通常是一个好的开始。