-
-
Save parndt/5285677 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is much cleaner refactor. I just learned a lot. Thanks my G!