ruby on rails - A model's name contains 'cache' -
in code, have model name contains string 'cache'. example:
class datacache < activerecord::base
and table name data_caches
. when run:
"data_caches".classify.constantize.new
to initialize model, error this:
nameerror: uninitialized constant datacach
why doesn't work? expected "datacache" got "datacach".
take @ inflections class in rails. add following text config/initializers/inflections.rb
class:
activesupport::inflector.inflections |inflect| inflect.irregular 'cache', 'caches' end
now in rails console try out word:
>> "caches".singularize => "cache" >> "cache".pluralize => "caches"
Comments
Post a Comment