app/models/notification.rb
# keep max 20 internal notifications for each user
keep max 20 internal notifications for each user
keep max 20 internal notifications for each user
def before_create
    limit = 19
    count = Notification.where("to_user_id = ? and internal = ?", to_user_id, 'Y').length
    return if count <= limit
    ns = Notification.where("to_user_id = ? and internal = ?", to_user_id, 'Y').order("updated_at desc")
    ns = ns[limit..-1]
    ns.each { |n| n.destroy }
  end
def before_create limit = 19 count = Notification . where ( "to_user_id = ? and internal = ?" , to_user_id , 'Y' ) . length return if count <= limit ns = Notification . where ( "to_user_id = ? and internal = ?" , to_user_id , 'Y' ) . order ( "updated_at desc" ) ns = ns [ limit .. - 1 ] ns . each { | n | n . destroy } end
keep max 20 internal notifications for each user
keep max 20 internal notifications for each user
# logger.debug2  "notification.before_create: to_user_id = #{to_user_id}" # keep newest 19 notifications (0..18). # one new notification will be created just in a moment