Skip to content

Instantly share code, notes, and snippets.

@leemcalilly
Created June 7, 2013 21:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leemcalilly/cfda1a7f15d87dbab731 to your computer and use it in GitHub Desktop.
Save leemcalilly/cfda1a7f15d87dbab731 to your computer and use it in GitHub Desktop.
class Work < ActiveRecord::Base
attr_accessible :client, :client_ids, :date, :description, :featured, :image, :name, :service
validates_presence_of :date, :client_ids, :name
validates_length_of :description, :in => 5..500, :allow_blank => true
validates_length_of :name, :in => 5..50
has_many :postings
has_many :clients, :through => :postings
mount_uploader :image, ImageUploader
after_save :enqueue_image
def image_name
File.basename(image.path || image.filename) if image
end
def enqueue_image
ImageWorker.perform_async(id, key) if key.present?
end
class ImageWorker
include Sidekiq::Worker
def perform(id, key)
work = Work.find(id)
work.key = key
work.remote_image_url = work.image.direct_fog_url(with_path: true)
work.save!
work.update_column(:image_processed, true)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment