ruby on rails - How to get all documents and hide this which are expired if they are defined? -
i want hide past events if defined , other. how show documents if :once_at nil , if :once_at defined hide these ones expired?
my recent approach, shows events defined :once_at, (i tryed :once_at => nil, without results):
default_scope where(:once_at.gte => date.today)
or (also not working)
default_scope excludes(:once_at.lte => date.today)
when think date.today
evaluated? if this:
default_scope where(:once_at.gte => date.today)
date.today
evaluated when class being loaded. never want happen, want date.today
evaluated when default scope used , usual way make happen use proc or lambda scope:
default_scope -> { where(:once_at.gte => date.today) }
the next problem documents don't have :once_at
or explicit nil
in :once_at
. nil
won't greater today you'd best check conditions separately :$or
query:
default_scope -> where( :$or => [ { :once_at => nil }, { :once_at.gte => date.today } ] ) end
Comments
Post a Comment