# Attempting ajax file upload

**URL:** <https://www.ruby-forum.com/t/attempting-ajax-file-upload/172730>\
**Category:** Rails\
**Created:** [July 27, 2009, 5:22am UTC](https://www.ruby-forum.com/t/attempting-ajax-file-upload/172730 "2009-07-27T05:22:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [July 27, 2009, 5:22am UTC](https://www.ruby-forum.com/t/attempting-ajax-file-upload/172730/1 "2009-07-27T05:22:16Z")

</div>

I have this basic code in place and it is giving me an:  
“undefined local variable or method `end\_form\_tag’ for  
#ActionView::Base:0x41a2094”

Note sure why I am getting the error as it is straight from:

> **[AJAX forms and file uploading in Rails](https://railsblaster.wordpress.com/2007/09/20/ajax-forms-and-file-uploading-in-rails/)**
>
> One very nice thing about Ruby on Rails is the support for AJAX. I consider myself a backend guy, so I don’t generally like to touch Javascript (though I’ve written my fair share of XMLHttpRequest …

view:

\<%= form\_remote\_tag(:url =\> { :controller =\> “image\_demo”, :action =\>  
“create” }, :html =\> {:multipart =\> true}) %\>  
**Picture:** &nbsp;  
\<%= file\_field\_tag “asset” %\>&nbsp;  
\<%= submit\_tag “Upload” %\>&nbsp;  
\<%= end\_form\_tag %\>

remote\_uploads.rb in lib directory:

module ActionView  
module Helpers  
module PrototypeHelper  
#alias\_method :form\_remote\_tag\_old, :form\_remote\_tag  
def form\_remote\_tag(options = {}, &block)  
unless options[:html] && options[:html][:multipart]  
form\_remote\_tag\_old(options, &block)  
else  
uid = “a#{Time.now.to\_f.hash}”  
\<\<-STR  
enctype=“multipart/form-data” target=“#{uid}” #{%(onsubmit=“#  
{options[:loading]}”) if options[:loading]}  
\>  
STR

```
    end
  end
end

```

end  
end

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [July 27, 2009, 5:53am UTC](https://www.ruby-forum.com/t/attempting-ajax-file-upload/172730/2 "2009-07-27T05:53:53Z")

</div>

On Jul 27, 4:21 am, Me [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have this basic code in place and it is giving me an:  
> “undefined local variable or method `end\_form\_tag’ for  
> #ActionView::Base:0x41a2094”

Because end\_form\_tag was removed from rails 2.0

Fred

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [July 27, 2009, 5:57am UTC](https://www.ruby-forum.com/t/attempting-ajax-file-upload/172730/3 "2009-07-27T05:57:59Z")

</div>

Ok, I changed to this but it is posting normally and not ajax for some  
reason. i see in the source that it is supposed to do an ajax submit.  
\<% form\_remote\_tag(:url =\> { :controller =\> “image\_demo”, :action =\>  
“create” }, :html =\> {:multipart =\> true}) do %\>  
**Picture:** &nbsp;  
\<%= file\_field\_tag “asset” %\>&nbsp;  
\<%= submit\_tag “Upload” %\>&nbsp;  
\<% end %\>

On Sun, Jul 26, 2009 at 10:52 PM, Frederick C. \<

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [July 28, 2009, 2:41am UTC](https://www.ruby-forum.com/t/attempting-ajax-file-upload/172730/4 "2009-07-28T02:41:51Z")

</div>

Stumped, the ajax submit works but does not pass the file param for  
some reason.

 \<% fields\_for :file, :html =\> { :multipart =\> true, :target=\>"upload\_file" } do %\> **Picture:** &nbsp; \<%= file\_field\_tag :upload %\>&nbsp; \<%= submit\_to\_remote 'up',"Upload", :method=\>'post', :url =\> { :controller =\> "rfi", :action =\> "sendfile", :id =\> @rfi }, :target=\>"upload\_file" %\>&nbsp; \<% end %\>
