Skip to content

Instantly share code, notes, and snippets.

@parndt
Forked from cue232s/gist:5285635
Last active December 15, 2015 15:59
Show Gist options
  • Save parndt/5285677 to your computer and use it in GitHub Desktop.
Save parndt/5285677 to your computer and use it in GitHub Desktop.
class PromotionAttachment < ActiveRecord::Base
belongs_to :promotion
attr_accessible :like_gate_image, :promotion_image, :app_icon, :video_url
validate :validate_like_gate_image_dimensions
[:like_gate_image, :promotion_image].each do |file_name|
options = {
styles: {
medium: "300x300>}",
thumb: "100x100>"
},
:url => "/system/:attachment/:id/:style.:extension",
}
# If ENABLE_S3 returns TRUE (config/initializers/_tmg.rb) then files will be sent to s3 otherwise they will be stored locally
options.update({
storage: :s3,
s3_credentials: "#{::Rails.root}/config/aws.yml"
}) if ENABLE_S3
has_attached_file file_name, options
end
protected
def validate_like_gate_image_dimensions #i'd like to be able to check that a like_gate_image meets the right dimensions
dimensions = Paperclip::Geometry.from_file(file.queued_for_write[:original].path)
# why are you setting these?
# self.width = dimensions.width
# self.height = dimensions.height
if dimensions.width != 810 && dimensions.height > 200
errors.add(:like_gate_image,'width must be equal to 810px, and the height must be atleast 200px.')
end
end
end
@cue232s
Copy link

cue232s commented Apr 1, 2013

This is much cleaner refactor. I just learned a lot. Thanks my G!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment