0

I have a list of records on a notification panel, i've used the gem public activity to populate the panel with these notifications, when a user clicks on one instance i redirect the user to a custom URL that will give details on that notification,on this redirection, i change the read column of that notification in the activities table to true

   def email_confirmed
     # loads one specific activity/notification using the id from the    url params
     @notification = load_activities.find(params[:id])
     # get the establishment,that is the trackable object,using activity id
     # get the establishment using the 'trackable_id' field in the    activities
     # table
     # Update the read column in the database on visit on the notification  details
     # view
     @notification.update_columns(read: true)
     @establishment_id = @notification.trackable_id
     # use this instance of an establishment in the 'view all' action view
    @establishment_details = Establishment.where(id:@establishment_id)
   end

I have a AJAX script running that deleted the read notifications

    setInterval(function(){
    $.ajax({
    url:'/notifications/remove_read_notifications',
    type: "GET",
    success: function(data){
         console.log("in side delete");
    }
   });

  },3000);

Now while im reading the notification table, i would like that if a user would refresh this page, it must not give an error that says the instance with "id" does not exist in the database, as there a way to circumvent this that will allow me to store that notification temporarily,help would be appreciated

Thabo
  • 1,303
  • 2
  • 19
  • 40

1 Answers1

1

The whole point of AJAX is for it to be asynchronous, but the behavior you are trying to accomplish is not consistent with that goal. Instead of using AJAX to delete the notifications use the notification's read status to dictate the presentation logic. If the user does not see it does not matter if the notification was deleted or not.

C dot StrifeVII
  • 1,885
  • 1
  • 16
  • 21
  • Cool that's what i did, and i'm only deleting in the database everyday at 2am using the delayed_job_cron gem – Thabo Oct 14 '16 at 07:30
  • Yea I thought about suggesting that but I did not know the nature of use for the app. There is a possibility that if someone is viewing a notification when that job is running that you recreate that issue. – C dot StrifeVII Oct 14 '16 at 11:31
  • O' boy..i'll have to do some tweaks there and there,thanks bro – Thabo Oct 17 '16 at 08:36