ferdy
ferdy

Reputation: 41

Tempory file share

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 ?

Upvotes: 0

Views: 66

Answers (1)

Roman Kiselenko
Roman Kiselenko

Reputation: 44370

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.

Upvotes: 1

Related Questions