I’m using paperclip for attachments for multiple models using accepts_nested_attributes_for. Is there a way I can specify specific paperclip style options for each model?
I’m using paperclip for attachments for multiple models using accepts_nested_attributes_for. Is there a way
Share
Yes. I use single table inheritance (STI) on sites for handling Audio, Video, and Images via an Asset model.
They all come into Rails as
:file, but the controller (A/V/I) knows to save to the proper model. Just remember that all attributes for any of the forms of media need to be included inAsset: if video doesn’t need captions but images do, then the caption attribute will be nil forVideo. It won’t complain.Associations will also work fine if hooked up to the STI models.
User has_many :videoswill operate the same as you are using it now, just make sure you don’t try to save to Asset directly.Lastly, since you do have an Asset model, you can still read directly from it if e.g. you want a list of the 20 most recent Assets. Also, this example isn’t restricted to separating media types, it can be used for different kinds of the same thing as well: Avatar < Asset, Gallery < Asset, and so on.