Skip to content

Instantly share code, notes, and snippets.

@abhas
Created December 12, 2011 10:36
Show Gist options
  • Save abhas/1466484 to your computer and use it in GitHub Desktop.
Save abhas/1466484 to your computer and use it in GitHub Desktop.
How to edit nested rails forms with file attachments
= f.fields_for :attachments do |att|
= att.label :file
- if att.object.new?
= att.file_field :file
- else
= att.object.file_name
@abhas
Copy link
Author

abhas commented Dec 12, 2011

I was working with a class which has_many attachments and accepts_nested_attributes_for them. The attachments just contain one field - an binary file attachment. I was extremely confused about how to handle the "edit view" of the form.

There is now way to pre-populate the filename of a file field via HTML. This is a good security measure. Its just that this took many hours (spread over as many days) to figure out how to enable a user to upload multiple files while showing the names and links to ones uploaded earlier.

A wonderful and fuzzy feeling of accomplishment!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment