簡體   English   中英

臨時存儲活動記錄實例以用於通知視圖

[英]Temporary store an active record instance for notification view

我在通知面板上有一個記錄列表,我使用gem public活動用這些通知填充面板,當用戶單擊一個實例時,我將用戶重定向到一個自定義URL,該URL將提供有關該通知的詳細信息,在此重定向上,我將活動表中該通知的read列更改為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

我正在運行一個AJAX腳本,該腳本刪除了已讀通知

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

  },3000);

現在,在即時消息讀取通知表的同時,我希望如果用戶刷新此頁面,它一定不能給出一個錯誤,指出數據庫中不存在帶有“ id”的實例,因為有一種方法可以避免這種情況請允許我暫時存儲該通知,我們將不勝感激

AJAX的全部要點是異步,但是您試圖實現的行為與該目標不一致。 與其使用AJAX刪除通知,不如使用通知的讀取狀態來指示表示邏輯。 如果用戶看不到,則通知是否已刪除都沒有關系。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM