Skip to content

Instantly share code, notes, and snippets.

@tayfunoziserikan
Created January 22, 2014 09:49
Show Gist options
  • Save tayfunoziserikan/8556075 to your computer and use it in GitHub Desktop.
Save tayfunoziserikan/8556075 to your computer and use it in GitHub Desktop.
Paperclip interpolations and attachment styles sample
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