File_field doesnt work inside form_remote_for

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?

Rajesh

The code difference is

<%
form_for :document, @document, :url => {:action =>
‘create’, :popup=>true}, :html => {:multipart => true}, :method =>
‘post’ do |f|
%>

<%
#form_remote_for :document, @document, :update => ‘content’, :url=>
{:action => ‘create’}, :html => {:multipart => true}, :method =>
‘post’ do |f|
%>

When the form_remote_for is commented the code works. When the
form_for is commented, code bombs saying Filename cannot be blank.

Regards,
Rajesh

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.

regards,

javier ramirez

Estamos de estreno… si necesitas llevar el control de tus gastos
visita http://www.gastosgem.com !!Es gratis!!

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.

Thanx for the quick response, Javier.

Regards,
Rajesh

On 14 Mar 2007, at 15:04, K. Rajesh wrote:

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.

Best regards

Peter De Berdt

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.

Regards,
Rajesh

On 15 Mar 2007, at 15:22, Russell N. wrote:

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? :slight_smile:

Best regards

Peter De Berdt

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”>

RSL

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. :slight_smile:

RSL

On 15 Mar 2007, at 12:27, K. Rajesh wrote:

What are the risks of using respond_to_parent? I am an absolute zero

I didn’t get it to work back in the old days (it’s been quite a while
since I’ve tried respond_to_parent), so I’m not the one you should
ask :slight_smile:

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.

You don’t have to know anything about Flash to use SWFUpload (http://
swfupload.mammon.se/).

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

Apply the hack you find at http://blog.inquirylabs.com/2006/12/09/
getting-the-_session_id-from-swfupload/ if you need to retain your
session.

Include the swfupload javascript in your HTML, then put something
like this in your view (and I’m doing :

http://pastie.caboo.se/47116

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.

The end result can be something like this:
http://www.10-forward.be/swfupload_rails.mov

Best regards

Peter De Berdt