Created
January 22, 2014 09:49
-
-
Save tayfunoziserikan/8556075 to your computer and use it in GitHub Desktop.
Paperclip interpolations and attachment styles sample
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 Model < ActiveRecord::Base | |
# Paperclip | |
has_attached_file :attachment, | |
:styles => {:large => "640x480#", :thumb => "320x240#"}, | |
:path => "/:class/:attachment/:style/:uniq_file_name.:extension" | |
validates_attachment_size :attachment, :less_than => 0..512.kilobytes | |
validates_attachment_content_type :attachment, :content_type => %w(image/jpeg image/jpg image/png application/pdf) | |
Paperclip.interpolates :uniq_file_name do |attachment, style| | |
attachment.instance.uniq_file_name | |
end | |
def uniq_file_name | |
Digest::SHA1.hexdigest(id.to_s) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment