I have an organization model with an association has_one :uploads, as: :uploadable
It's a polymorphic relationship to
class Upload < ApplicationRecord
include Uploaders::StandardUploader::Attachment.new(:file)
belongs_to :uploadable, polymorphic: true, touch: true, optional: true
end
Everything works fine in terms of creating a record, but when I edit:
= form.fields_for :upload, organization.upload do |form_upload|
= form_upload.label :file
= form_upload.file_field :file
span Choose file...
The controller calls build_upload
in the edit method, which builds a new association and actually destroys the existing one.
If I don't call build_upload
, the form upload fiels are blank.
I'm at a loss of what's going on...what can I do to prevent the destroy on a has_one
so the existing upload isn't lost?
What should I do to ensure the form fills in the existing upload?