Forum: Ruby on Rails Advice about upload form

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D75f4b92f64038bcb02995694c1c9984?d=identicon&s=25 Jeroen Janssen (joran)
on 2009-01-14 11:48
(Received via mailing list)
I have Article model that has_many images.

The edit page for an article has two different forms, one for the
article itself and another for uploading images. The upload-form
uploads an image and redirects to the edit page. I did this to make it
easy to make links to images in the text of the article.

The problem of this design is when a user enters some info in the
article form and doesn't submit the form, if the user subsequently
uploads an images the entered info gets lost.

I've thought of a couple of solutions to this problem:

Upload the images via AJAX
-----------------------------------------
Uploading via AJAX is not really possible but there are some
workarounds with hidden iFrames. This feels a bit hackish, but it
might be the best solution.

Also send the article form when uploading
-------------------------------------------------------------
When uploading a file I could also send the article form to the upload
action. I could then make a new @article object (without saving it)
and use that to repopulate the form after the redirect. Problem is, I
have no idea to send the fields/values from one form together with an
other form and I can't find anything about doing this.




Could somebody give me some tips? Maybe I'm going about this all
wrong, I feel I'm overlooking a simple solution.
This topic is locked and can not be replied to.