Tempory file share

荒凉一梦 提交于 2020-01-06 19:48:41

问题


Hi i am building an ruby on rails application.I wants to share an attachment for a maximum of one hour only,thereafter that particular link must be deactivated. is that possible to achieve this without doing any CRON job?

My requirement is user can upload attachments and they can share the encrypted URL.the maximum validity of that URL will be one hour.

I want to know that whether it is possible by without creating any CRON job? if yes please help me ?


回答1:


you can use application controller helper before_filter

class ApplicationController < ActionController::Base
  before_filter :check_expire

  def check_expire
    UrlLink.active.where('expire_time <= ?' Time.now).find_each do |url|
      url.deactive!
    end if UrlLink.active.any?
  end
end

model

class UrlLink < AB
  scope :active, -> { where(active: true) }

  def deactive!
    update(active: false)
  end
end

but this work slow if you have large db.



来源:https://stackoverflow.com/questions/21361550/tempory-file-share

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!