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 - How to save instance state of selected radiobutton on menu -

python 3 IndexError: list index out of range -

IF statement in MySQL trigger -