Ruby comparing dates -


I want to know whether the user has been created in the system in the last 10 seconds. So I will do this:

  def new_user if (datetime.Now - User.created_at & lt; 10) true will return true false end and  

IT only One idea, how can I do this correctly? Thanks

  class user & lt; ActiveRecord :: Base Def New? Made_t & gt; 10.seconds.ago and end # example: user = user Create! User.new? # = & Gt; True sleep is 11 user.new? # = & Gt; False  

(Consider your user class as an ActiveRecord model.)


Comments