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

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -