Skip to content

Instantly share code, notes, and snippets.

@coop
Created October 19, 2012 04:25
Show Gist options
  • Save coop/3916233 to your computer and use it in GitHub Desktop.
Save coop/3916233 to your computer and use it in GitHub Desktop.
class Page < ActiveRecord::Base
has_attached_file :image
end
class DelayedAttachment
attr_reader :attachment
def initialize attachment
@attachment = attachment
end
def delay
attachment.halt_processing!
DelayedJob.enqueue SomeJob.new(attachment.instance.class, attachment.instance.id)
end
end
class SomeJob
def initialize klass, id
@klass, @id = klass, id
end
def perform
@klass.find(@id).reprocess!
end
end
class PagesController < ApplicationController
def create
@page = Page.find params[:id]
if @page.image_changed?
DelayedAttachment.new(@page.image).delay
end
@page.save
redirect_to page_path(@page)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment