0

Rails 5 here。Rails 5枚舉模型的關注內生成NameError:未初始化的常量

我試過沒有運氣加載我的用戶模型(設計模型)內的關注。 include Levelable在其他型號上沒有任何問題。 我必須配置一個特殊的配置/幫助程序/初始化程序關於這個特殊的模型,使其工作?

模式關注Levelable所使用的機型用戶和客戶端

#models/concerns/levelable.rb 
require 'active_support/concern' 

    module Levelable 
     extend ActiveSupport::Concern 

    included do 
    enum level: { beginner: 0, intermediate: 1, advanced: 2, very_advanced: 3 } 
    end 
end 

和模型(縮短可讀性)

#models/user.rb 
class User < ApplicationRecord 

    # Include default devise modules. Others available are: 
    # :confirmable, :lockable, :timeoutable and :omniauthable 
    devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable 

    include Levelable 

    acts_as_messageable 
end 

這種設置的結果是:在客戶端模式發生NameError: uninitialized constant User::Levelable 同樣的錯誤所以我猜想有些東西不符合我的擔憂。 我已經試過自動加載config/application.rb裏面的路徑,沒有任何改變。

我不知道如何使擔憂的工作負載,任何幫助將是偉大的。謝謝 !

回答

0

我前段時間有過這個問題,經過一番挖掘後,我發現我的關注文件使用大寫形式命名(出於一些瘋狂的原因)。

因此,我將它們從Searchable.rb更名爲searchable.rb,全部完成! :)

PS。如果您使用git/github,diff不區分大小寫,所以如果您將它們從Levelable.rb重命名爲levelable.rb,它將不會出現在git status中。

乾杯

+0

很明顯就是這樣。謝謝你的提示! – Patient55