2016-11-19 24 views
0

我有一個基本的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 

回答

1

嗯,問題出在Heroku服務器配置中。看起來像Heroku阻止常量名稱Persistable。一旦我將每次發生的Persistable重命名爲Archivable,它就開始工作。

0

這應該給你一個提示:

uninitialized constant Address::Persistable (NameError)

它試圖找到Address中的模塊出於某種原因。明確要求頂級Persistable

class Address < ApplicationRecord 

    include ::Persistable 
+0

謝謝!但錯誤仍然以不同的形式出現:''/app/app/models/address.rb:3:in'':未初始化的常量Persistable(NameError)'''。我應該在哪裏看? – Max

+0

@Max:似乎你的autoload_paths被搞亂了。我現在看看。 –

+0

好的,添加了問題.. – Max