File-uploads in rails 2.0.2 + AJAX

hi,

I am porting an app from 1.2.5 to 2.0.2 and I am having problems with
file
uploads. The form fields look like this:

<%= ‘Add attachment’.t %>: <%= file_field ‘attachments’, “upload#{id}”,
:size => ‘40’ %>

The old code expects params[:attachments][“upload#{i}”] to be an object
(File?)
with a method “original_filename”.
I am using ajax (and previously didn’t):

<% form_remote_tag(:url => url_for(:controller => :mex, :action =>
:submit_answer, :id => mex_exercise.id), :update =>
“answer_#{mex_exercise.id}”, :html => {:multipart =>
mex_exercise.num_attachments_allowed > 0}) do %>

(num_attachments_allowed is > 0 and I see the enctype-attribute:

)

Do I need to change anything because of ajax?

thanks,


Felix N.

On 12 Feb 2008, at 14:22, Felix N. wrote:

The old code expects params[:attachments][“upload#{i}”] to be an

)

Do I need to change anything because of ajax?

File uploads can’t be done over ajax (because the javascript isn’t
allowed to read files from your computer). There are tricks you can
play with iframes and so on.

Fred

On 12 Feb 2008, at 15:22, Felix N. wrote:

I am using ajax (and previously didn’t):
parameters:Form.serialize(this) + ‘&authenticity_token=’ +
encodeURIComponent(‘a5de291b429a9def0d4ff822d8e278172e472a28’)});
return false;">

)

Do I need to change anything because of ajax?

Indeed as another poster has already mentioned you can’t upload files
through ajax (javascript security).

Either use a Flash uploader like swfupload.org (but if you’re not
fairly fluent in Javascript, i would advise against it), do know that
the new session security measures cause problems if you want the
upload to be authenticated or search for the responds_to_parent
plugin and follow the instructions.

Best regards

Peter De Berdt

I also use v2.0.2 and have problem with remote file upload. I followed
the instructions from this page
http://khamsouk.souvanlasy.com/2007/5/1/ajax-file-uploads-in-rails-using-attachment_fu-and-responds_to_parent
and getting error
undefined method content_type' in vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:260:in uploaded_data

anybody handled this problem in rails 2 ?

Marek