0

I am trying to add to the activity canceled value with after_destoy in observer class, but no value come through to display. if the booking is deleted, the booking flagged as canceled. Any idea how to add the canceled value to the activity with after_destroy?

Many thanks.

This is my observer class:

 class BookingObserver < ActiveRecord::Observer
  def after_destroy(booking)
     Activity.add(booking.venue, booking.created_by, 
     Activity::BOOKING_CANCELLED, booking) unless booking.imported?
  end
  def after_create(booking)

   Activity.add(booking.venue, booking.created_by, 
   Activity::BOOKING_CREATED, booking) unless booking.imported?
  end
 def after_update(booking)
  Activity.add(booking.venue, booking.created_by, 
  Activity::BOOKING_UPDATED, booking) unless booking.imported?
 end
end
gerzson
  • 1
  • 2

1 Answers1

0

1- You can refer gem acts_as_paranoid for handling this situation. It will easy to manage destroy(it will updated deleted at) and really_destroy(destroy the booking).

  1. You create method Cancel and update the deleted value of the object and use same for fetching cancel bookings object.
Atul Shukla
  • 171
  • 1
  • 8
  • Thanks for that, I tried those options, but if I user after_destroy option, the values disappear, however in the console the data still exist, only flagged as canceled. – gerzson Aug 13 '17 at 15:31
  • Can you paste screenshot of console. I want to clear my mind also. – Atul Shukla Aug 14 '17 at 16:31