-
-
Save leemcalilly/cfda1a7f15d87dbab731 to your computer and use it in GitHub Desktop.
This file contains 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 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