There are a lot of good resources out there that show how to create a Rails application with multiple image uploads. Additionally, there are a lot of good resources showing how to use paperclip to upload different file types (PDF, image, .Doc).
I'd like to create an application where a User has an image asset for their profile picture, and also has the ability to upload PDFs or .Doc files to their account to be tied to the User. Has anyone had experience with this to confirm it's possible through the Paperclip gem? Any tutorials or resources to point me in the right direction would be appreciated.
I was also having exactly same problem like you. No need to do extra coding for this, just add following
has_attached_file :attachment,
:styles => lambda{ |a|
["image/jpeg", "image/png", "image/jpg", "image/gif"].include?( a.content_type ) ? {
:thumb=> "100x100#",
:small => "150x150>",
:medium => "300x300>",
:large => "500x500>" }: {}
}
Let me know if you need further explanations.
Just in case anyone is looking at this recently, we have just tried the accepted answer, and the content types did not work properly. We got it working like this:
has_attached_file :attachment, styles: lambda { |a| a.instance.attachment_content_type =~ %r(image) ? {:small => "x200>", :medium => "x300>", :large => "x400>"} : {} }
The difference is in the "column name" for the object -- typically "___content_type", instead of just "content_type"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With