我有一个基本的 Rails 应用程序,我正在尝试将关注点用于干燥模型。在开发环境中一切正常,但是当我尝试将应用程序上传到 Heroku 时,它不断给我这个错误:
/app/app/models/address.rb:3:in `<class:Address>': uninitialized constant Address::Persistable (NameError)
我试图禁用急切加载,但没有帮助。
这是我的地址模型:
class Address < ApplicationRecord
include Persistable
belongs_to :city
belongs_to :company
validates :city_id, :human, :lat, :lng, presence: true
end
这是我命名为“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
我已经做了什么:
- 试图关闭急切加载
- 试图将
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