我有一个基本的Rails应用程序,我试图用干燥模型的担忧。一切都在开发环境中去,但是当我尝试上传应用程序到Heroku的,它不断给我这个错误:关注未在Rails 5中加载
/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
这里是我命名为 “持久化” 模块,位于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
路径自动加载配置
没有工作,我仍然有这个问题!
UPDATE
我做了命令形式guiderails 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
谢谢!但错误仍然以不同的形式出现:''/app/app/models/address.rb:3:in'':未初始化的常量Persistable(NameError)'''。我应该在哪里看? –
Max
@Max:似乎你的autoload_paths被搞乱了。我现在看看。 –
好的,添加了问题.. – Max