# Controller method/action being called twice (once POST and once GET) for file upload - why?

**URL:** <https://www.ruby-forum.com/t/controller-method-action-being-called-twice-once-post-and-once-get-for-file-upload-why/153178>\
**Category:** Rails\
**Created:** [November 13, 2008, 12:08am UTC](https://www.ruby-forum.com/t/controller-method-action-being-called-twice-once-post-and-once-get-for-file-upload-why/153178 "2008-11-13T00:08:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 13, 2008, 12:08am UTC](https://www.ruby-forum.com/t/controller-method-action-being-called-twice-once-post-and-once-get-for-file-upload-why/153178/1 "2008-11-13T00:08:17Z")

</div>

I’m uploading a file via the user’s browser. The index method in my  
controller is:

\<%= form\_tag({:action=\>‘receive\_file’}, :multipart =\> true)%\>

  

I get a form with a ‘browse’ button and an ‘upload’ button. I use the  
browse control to select a file and I press the ‘upload’ button.

The method ‘receive\_file’ in my controller gets called (with method  
GET) and executes, then passes control to the corresponding view so  
far so good.

The strange thing is that behind the scenes, something immediately  
calls my ‘receive\_file’ method a second time (this time with method  
POST).

Why is this hapenning? How am I supposed to handle it? I don’t want to  
execute my receive\_file method twice.

Thanks for your help,  
Yoram

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 13, 2008, 2:01am UTC](https://www.ruby-forum.com/t/controller-method-action-being-called-twice-once-post-and-once-get-for-file-upload-why/153178/2 "2008-11-13T02:01:44Z")

</div>

per the subject line, further investigation reveals that all the  
methods in my controller that i am using, are called exactly twice  
each time i expect them to be called once. i am confused…

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 13, 2008, 2:49am UTC](https://www.ruby-forum.com/t/controller-method-action-being-called-twice-once-post-and-once-get-for-file-upload-why/153178/3 "2008-11-13T02:49:05Z")

</div>

On Nov 13, 1:00 am, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> per the subject line, further investigation reveals that all the  
> methods in my controller that i am using, are called exactly twice  
> each time i expect them to be called once. i am confused…

Anything interesting in your controller? Can you see (using tcpdump or  
whatever your platform has) whether the browser is actually making two  
requests ?

Fred

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 13, 2008, 3:08am UTC](https://www.ruby-forum.com/t/controller-method-action-being-called-twice-once-post-and-once-get-for-file-upload-why/153178/4 "2008-11-13T03:08:58Z")

</div>

Fred, thanks:

Well - per your suggestion, I turned net tracking on in firebug (I’m  
using firefox). And the problem went away… like Heisenberg said :-).

Sorry for bothering the list with such artifact.

It’s a little scary to see the browser get in to such a state  
though…

Y

On Nov 12, 5:48 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
