I can think of a couple ways to handle this but it mainly has to do with what the end product is trying to accomplish.
First I would use the shrine plugin, :determine_mime_type, to determine the file type.
Then you could either continue with your current approach of separating the files in to two separate models or you could set a field called "file_type" on your Attachment model. An attachment is either an "image" or a "document". Then you could create a scope on your Project model for attachments that queries file_type on the association, one for images and one for documents .
This allows you to then simply call project.images or project.documents.
Just my 2 cents and what came to mind when I read your question
Thanks a whole bunch for doing this series. Invaluable! Exactly what I needed.
Posted in Our First API (Example) - GoRails
Love to see file uploads through an API. If it was possible to do direct to S3 that would be the icing on the cake.
Thanks for connecting all the dots on this one! Really appreciate it.
I'm not tied to jQuery. Dropzone looks very cool. Just like to be able to do a direct upload to S3 with multiple file drag and drop / background upload/processing. Sounds like that's where you are headed with the videos, so I am down. Thanks!
Thanks, Chris. The direct upload to S3 with JQuery has been on my list for awhile to figure out. It will be much appreciated!
Request as you build the next few in the series that, if possible, you cover:
1) Direct upload to S3
2) JQuery/Multi-File/Background uploading