1

On attempting to locate a model via rails console

>> f = DBFile.find_by_id(1)
>> NameError: uninitialized constant DBFile
>> D_B_File.all()
LoadError: Expected /home/thrive/rails_projects/tester/app/models/d_b_file.rb to define D_B_File
>> f = DBFile.find_by_id(1)
#<DBFile id: 1, file_name: "output-May-2010.csv">

Now when I rename the model d_b_file.rb >> db_file.rb

>> f = DBFile.find_by_id(1)
#<DBFile id: 1, file_name: "output-May-2010.csv">

So what about the additional underscore in the original model name ...is preventing it from loading normally?

4

1 に答える 1

1

問題は、ファイル名がクラス名に直接関係していることです。これは、Rails がクラスを探す場所を決定するためにファイル名に依存しているためです。

だから、"DBFile".underscoreあなたを与えるでしょうdb_file。そのため、Rails はそのクラスが見つかることを期待しています。

于 2012-09-17T14:35:20.733 に答える