Date within range + Rails

Here is a basic example to determine whether todays date feature within a particular range.

Creating an instance method inside model, this method will return true or false
def notification_required?
    start_date = 15.days.ago.to_date
    end_date = Date.today
    (start_date..end_date).include_with_range?(self.last_notification_sent_at)
  end
And to use this method
@user.notification_required?

 

Comments

Popular posts from this blog

Inserting and Moving elements inside Ruby Array

Remove duplicates from a JavaScript Array

Sending Binary Data over the Network with Json