Is there how to upload files using ajax?

I’am trying to send multipart with ajax like this
<%= form_remote_tag :url => {:action => “upload” } %>

<%= file_filed “user”, “picture” %>

<%= submit_tag %>
<%= end_form_tag %>

But when i try get @params[:user][:picture] the value is nil

Anyone can help me

Bruno

I don’t know whether you can upload files via ajax, but you misspelt
‘file_field’… might be part of the problem if this is copied & pasted
from your code…

On 26 Aug 2006, at 14:29, Bruno M. wrote:

I’am trying to send multipart with ajax like this
<%= form_remote_tag :url => {:action => “upload” } %>

<%= file_filed “user”, “picture” %>

<%= submit_tag %>
<%= end_form_tag %>

But when i try get @params[:user][:picture] the value is nil

AJAX uploads are not supported out of the box, you can check this
page for help: http://sean.treadway.info/demo/upload/ and http://
sean.treadway.info/svn/plugins/responds_to_parent/README

Best regards

Peter De Berdt

Peter De Berdt wrote:

On 27 Aug 2006, at 05:15, Jonathon M. wrote:

Peter can you provide a simple example? Are you using file_column?
Im not very familiar with javascript so Id like to see a real :update
loop.

Install the plugin by entering “script/plugin install http://
sean.treadway.info/svn/plugins/responds_to_parent/” in the terminal.

The readme of respond_to_parent will show you how to use it:
http://sean.treadway.info/svn/plugins/responds_to_parent/README

If you’re really uncomfortable with all of this, just use the normal
form submit (don’t use ajax). It will be hard to maintain something
if you don’t understand how it works.

Best regards

Peter De Berdt

I’ve read the readme and even created a project thats exactly the same.
This line results not one but two RJS template errors.

page << “alert($(‘stuff’).innerHTML)”

Peter can you provide a simple example? Are you using file_column?
Im not very familiar with javascript so Id like to see a real :update
loop.

Peter De Berdt wrote:

On 26 Aug 2006, at 14:29, Bruno M. wrote:

I’am trying to send multipart with ajax like this
<%= form_remote_tag :url => {:action => “upload” } %>

<%= file_filed “user”, “picture” %>

<%= submit_tag %>
<%= end_form_tag %>

But when i try get @params[:user][:picture] the value is nil

AJAX uploads are not supported out of the box, you can check this
page for help: http://sean.treadway.info/demo/upload/ and http://
sean.treadway.info/svn/plugins/responds_to_parent/README

Best regards

Peter De Berdt

On 27 Aug 2006, at 05:15, Jonathon M. wrote:

Peter can you provide a simple example? Are you using file_column?
Im not very familiar with javascript so Id like to see a real :update
loop.

Install the plugin by entering “script/plugin install http://
sean.treadway.info/svn/plugins/responds_to_parent/” in the terminal.

The readme of respond_to_parent will show you how to use it:
http://sean.treadway.info/svn/plugins/responds_to_parent/README

If you’re really uncomfortable with all of this, just use the normal
form submit (don’t use ajax). It will be hard to maintain something
if you don’t understand how it works.

Best regards

Peter De Berdt

I’ve read the readme and even created a project thats exactly the
same.
This line results not one but two RJS template errors.

page << “alert($(‘stuff’).innerHTML)”

Tsk tsk tsk, the readme is a quick and dirty draft, the form wasn’t
set to multipart, but as soon as you replace it with rails style erb
tags, everything runs fine.

Example:

class TestController < ApplicationController

def main
end

def form_action
# Do stuff with params[:uploaded_file]
if params[:uploaded_file]
responds_to_parent do
render :update do |page|
page << “alert(’#{params
[:uploaded_file].original_filename}’)”
end
end
else
render :nothing => true
end
end

end

main.rhtml

<title>Test</title>
Here is some stuff
 <%= start_form_tag({:action => 'form_action'}, :multipart =>

true, :target => “frame”) %>
<%= file_field_tag(“uploaded_file”)%>
<%= submit_tag(‘Save’)%>
<%= end_form_tag %>

 <iframe id='frame' name="frame"></iframe>

Best regards

Peter De Berdt

You need include defaults javascript library to fix the rjs erors.

Best regards

Peter De Berdt

I’ve read the readme and even created a project thats exactly the same.
This line results not one but two RJS template errors.

page << “alert($(‘stuff’).innerHTML)”