サブフォルダー内のモデルへのアクセスに関して、この問題が発生しています。私のプロジェクトには次のファイル構造があります。
app/models
- accounts
- type1.rb #Inherits from Account
- type2.rb #Inherits from Account
- etc.
- account.rb
- user.rb
- etc.
user.rb には、type1 または type2 のアカウントを作成しようとする関数があります。
def function
self.account = ::Type1.new(...)
end
application.rb に ( http://blog.hasmanythrough.com/2008/5/6/a-simple-alternative-to-namespaced-modelsに従って) 次の行を追加したことを知っています。
config.autoload_paths += Dir["#{config.root}/app/models/**/"]
モデルのサブフォルダーが実際に読み込まれるようにします。
今でもuninitialized constant Type1
、関数を呼び出すと、有名なエラー メッセージが表示されます。私は何が欠けていますか?
アップデート:
Type1 クラスは空です:
class Type1 < Account
end
Account クラスは単純です。
class Account < ActiveRecord::Base
#======================RELATIONS======================
belongs_to :currency
belongs_to :organization
#======================VALIDATIONS=========================
validates :name, :presence => true
validates :country, :presence => true
validates :currency, :presence => true
validates :organization, :presence => true
end