secret
Created

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.