Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Set custom Paperclip attachments style based on specific attribute extra value.
class Attachment < ApplicationRecord
has_attached_file :file,
styles: ->(a) { a.instance.paperclip_styles },
path: 'public/system/:class/:id/:style_:filename',
url: '/system/:class/:id/:style_:filename'
validates_attachment_presence :file
def paperclip_styles
case typology
when 'profile'
{
thumb: '200x200>'
}
when 'cover'
{
thumb: '200x200>'
medium: '600x400>'
}
when 'post_image'
{
medium: '600x400>'
}
else
{}
end
end
after_create do
file.reprocess!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.