Forum: Ruby on Rails Controller method/action being called twice (once POST and once GET) for file upload - why?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9d12e24c0a3aebe28b58682d517acdfb?d=identicon&s=25 ybernet@msn.com (Guest)
on 2008-11-13 00:08
(Received via mailing list)
I'm uploading a file via the user's browser. The index method in my
controller is:


  <%= form_tag({:action=>'receive_file'}, :multipart => true)%>
     <input type="file" name="user_data_file" />
     <p></p>
     <input type="submit" value="Upload" />
  </form>

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
9d12e24c0a3aebe28b58682d517acdfb?d=identicon&s=25 ybernet@msn.com (Guest)
on 2008-11-13 02:01
(Received via mailing list)
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...
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-11-13 02:49
(Received via mailing list)
On Nov 13, 1:00 am, "yber...@msn.com" <yber...@msn.com> 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
9d12e24c0a3aebe28b58682d517acdfb?d=identicon&s=25 ybernet@msn.com (Guest)
on 2008-11-13 03:08
(Received via mailing list)
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 Cheung <frederick.che...@gmail.com>
This topic is locked and can not be replied to.