When I do file_field within a form_for things are fine... but within a
form_remote_for, with nothing else changed, I find that the params
does not even have the element document[uploaded_file] even though it
is definitely present in the HTML source in the form. Obviously the
file upload fails.
Am I missing something? Or has someone else faced this? Or is this a
known bug?
When I do file_field within a form_for things are fine... but within a
form_remote_for, with nothing else changed, I find that the params
does not even have the element document[uploaded_file] even though it
is definitely present in the HTML source in the form. Obviously the
file upload fails.
it doesn't really fails.. by design you cannot upload a file via ajax (security concerns). One known workaround is using a hidden frame so you can submit your form against it. There are some plugins that allow you to do that automatically. If memory serves me well, I'd say you can combine acts_as_attachment with respond_to_parent for example. Anyhow, by googling by ajax rails file upload you can propably get some more references.
Mmmm... I didnt know file uploads were not supposed to Ajax... I never
thought to search that out! I was shocked thinking there was a bug in
Rails. A BUG IN RAILS, I thought!!!
Anyways... I got this done with just respond_to_parent. Considering
that my site will host on a shared Apache, I am wondering whether it
is safe to implement upload_progress plugin. In development I use
Mongrel. I dont want to run into environment issues because at this
time upload_progress is not a VITAL feature, it is just a nice-to-
have.
In case you’re going to host on a shared server, I would seriously advise you to use Flash (SWFUpload in particular) for multiple file upload (with filter and max filesize) and upload progress. As a client-side technology, you don’t have to rely on serverside intricacies and it works wonderfully.
What are the risks of using respond_to_parent? I am an absolute zero
on Flash. I dont even know how to get the flash thingies on to the
screen and I would rather not go into it, unless I have to have to
have to.
That being said, you do have to rely on a user having Flash installed and having it enabled. Not a huge assumption but not more safe than assuming the user has JS active and we all know that’s not a given. </cents size=“two”>
Just like it would be a very huge assumption that a shared host would do you a favor and install or recompile a webserver because you want upload progress, right?
Hwhat? I must have missed something. Why would you have to recompile the server to use upload progress? But it would indeed be a huge assumption that the host would do such a favor for you.
Just download the zip file on the site, open the javascript file and change the path to /javascripts/SWFUpload/upload.swf so that it follows rails conventions (this assumes you put the SWFUpload for in the public/javascripts/ folder of your rails app
SWFUpload will prompt the user to install flash if it’s not installed, as well as allow you to use a replacement normal file field in case Javascript is disabled.