Created
October 19, 2012 04:25
-
-
Save coop/3916233 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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