在我的代碼中,我有一個模型,其名稱包含字符串'cache'。例如:模型的名稱包含'cache'
class DataCache < ActiveRecord::Base
和表名是data_caches
。當我運行:
"data_caches".classify.constantize.new
初始化模式,我得到這樣一個錯誤:
NameError: uninitialized constant DataCach
爲什麼不這項工作?我預計「DataCache」,但得到「DataCach」。