Created
December 12, 2011 10:36
-
-
Save abhas/1466484 to your computer and use it in GitHub Desktop.
How to edit nested rails forms with file attachments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= f.fields_for :attachments do |att| | |
= att.label :file | |
- if att.object.new? | |
= att.file_field :file | |
- else | |
= att.object.file_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was working with a class which
has_many
attachments andaccepts_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!