简体   繁体   中英

Temporary store an active record instance for notification view

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM