Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View my_model.rb
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
class MyModel < ActiveRecord::Base
 
# Paperclip saves its attachments after_save. after_create fires before
# after_save, so we need to fake an after_create after paperclip's
# after_save
 
has_attached_file :some_s3_stuff
before_create :set_as_being_created
after_save :run_through_zencoder
attr_accessor :last_response
 
def set_as_being_created
@being_created = true
end
 
def run_through_zencoder
if @being_created
begin
@last_response = Zencoder::Job.create
if @last_response.success?
@being_created = false
true
else
@being_created = false
raise ActiveRecord::Rollback
end
rescue Zencoder::HTTPError
@being_created = false
raise ActiveRecord::Rollback
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.