# Is there how to upload files using ajax?

**URL:** <https://www.ruby-forum.com/t/is-there-how-to-upload-files-using-ajax/66520>\
**Category:** Rails\
**Created:** [August 26, 2006, 2:29pm UTC](https://www.ruby-forum.com/t/is-there-how-to-upload-files-using-ajax/66520 "2006-08-26T14:29:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lenrek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a183cd/32.png) [@lenrek](https://www.ruby-forum.com/u/lenrek)\
**Post date:** [August 26, 2006, 2:29pm UTC](https://www.ruby-forum.com/t/is-there-how-to-upload-files-using-ajax/66520/1 "2006-08-26T14:29:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lenrek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a183cd/32.png) [@lenrek](https://www.ruby-forum.com/u/lenrek)\
**Post date:** [August 26, 2006, 4:28pm UTC](https://www.ruby-forum.com/t/is-there-how-to-upload-files-using-ajax/66520/2 "2006-08-26T16:28:48Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![lenrek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a183cd/32.png) [@lenrek](https://www.ruby-forum.com/u/lenrek)\
**Post date:** [August 26, 2006, 6:43pm UTC](https://www.ruby-forum.com/t/is-there-how-to-upload-files-using-ajax/66520/3 "2006-08-26T18:43:09Z")

</div>

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/](http://sean.treadway.info/demo/upload/) and http://  
sean.treadway.info/svn/plugins/responds\_to\_parent/README

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![lenrek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a183cd/32.png) [@lenrek](https://www.ruby-forum.com/u/lenrek)\
**Post date:** [August 27, 2006, 8:23pm UTC](https://www.ruby-forum.com/t/is-there-how-to-upload-files-using-ajax/66520/4 "2006-08-27T20:23:22Z")

</div>

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](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)”

---

<div class="post-metadata">

**Author:** ![lenrek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a183cd/32.png) [@lenrek](https://www.ruby-forum.com/u/lenrek)\
**Post date:** [August 27, 2006, 5:15am UTC](https://www.ruby-forum.com/t/is-there-how-to-upload-files-using-ajax/66520/5 "2006-08-27T05:15:00Z")

</div>

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/](http://sean.treadway.info/demo/upload/) and http://  
> sean.treadway.info/svn/plugins/responds\_to\_parent/README
> 
> Best regards
> 
> Peter De Berdt

---

<div class="post-metadata">

**Author:** ![lenrek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a183cd/32.png) [@lenrek](https://www.ruby-forum.com/u/lenrek)\
**Post date:** [August 27, 2006, 1:36pm UTC](https://www.ruby-forum.com/t/is-there-how-to-upload-files-using-ajax/66520/6 "2006-08-27T13:36:22Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![lenrek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a183cd/32.png) [@lenrek](https://www.ruby-forum.com/u/lenrek)\
**Post date:** [August 27, 2006, 9:17pm UTC](https://www.ruby-forum.com/t/is-there-how-to-upload-files-using-ajax/66520/7 "2006-08-27T21:17:10Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![lenrek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a183cd/32.png) [@lenrek](https://www.ruby-forum.com/u/lenrek)\
**Post date:** [August 29, 2006, 6:50am UTC](https://www.ruby-forum.com/t/is-there-how-to-upload-files-using-ajax/66520/8 "2006-08-29T06:50:58Z")

</div>

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