Tempory文件共享 [英] Tempory file share

查看:229
本文介绍了Tempory文件共享的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在rails应用程序上构建一个ruby。我想要共享一个附件最多只有一个小时,之后必须停用特定的链接。
是可以实现这一点,而不做任何 CRON工作



我的要求是用户可以上传附件,他们可以共享加密的URL。该URL的最大有效性将是一个小时。



我想知道是否可以通过不创建任何 CRON作业?如果是,请帮助我?

解决方案

可以使用应用程序控制器助手 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!
结束如果UrlLink.active.any?
end
end

模型

 类UrlLink< AB 
范围:活动, - > {where(active:true)}

def deactive!
update(active:false)
end
end

如果你有大数据库,这个工作会慢一些。


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 ?

解决方案

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.

这篇关于Tempory文件共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆