ruby on rails - how to dynamic create a mongoid class? -


i want dynamic create mongoid model , search.

at first, create file named daily_pageview.rb

class dailypageview   include mongoid::document   include mongoid::timestamps   field :path, type: string end 

then, run these commands in $ rails c

dailypageview.create!(path: '/') dailypageview.where(:path => '/').count 

correctly, got result: 1.

then try refactor code, delete daily_pageview.rb

also, run these commends in rails c

c = class.new    include mongoid::document    include mongoid::timestamps    field :path, type: string end object.const_set 'dailypageview', c    dailypageview.where(:path => '/').count 

but, time, got 0. why?

i'm not sure related issue mongoid failing dynamic collections or problem.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -