ruby on rails - Ignoring created_at timestamp when working with a Datetime field object -
ruby on rails - Ignoring created_at timestamp when working with a Datetime field object -
in ticketing app built using rails 4.1, there 2 datetime fields (booking_start_date , booking_end_date). utilize next code ensure availability of tickets , update status:
def check_start_date if(self.booking_start_date >= datetime.now && datetime.now < self.booking_end_date) if(self.ticket_quantity.to_i > 0) self.status = 'open' else self.status = 'sold out' end elsif(datetime.now < self.booking_start_date) self.status = 'booking available soon' elsif(datetime.now >= self.booking_end_date) self.status = 'closed' end end
often takes few minutes user fill ticket creation form. so, if user starts @ 10.30 (which auto populated in booking_start_date field) , takes till 10.35 create form, status of ticket stays empty. put, long booking_start_date atleast min ahead of created_at date, status gets updated. how ensure scenario taken business relationship well?
if want add together logic run when booking_start_date atleast min ahead of created_at date add together elsif , write like:
elsif(self.created_at + 1.days < self.booking_end_date) # logic
i hope answers question, if not leave comment , i'll update answer.
ruby-on-rails
Comments
Post a Comment