我有一个基本的 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)
我已经做了什么: …