# Routing/File Upload/Put vs. Post puzzle

**URL:** <https://www.ruby-forum.com/t/routing-file-upload-put-vs-post-puzzle/182101>\
**Category:** Rails\
**Created:** [January 22, 2010, 5:48pm UTC](https://www.ruby-forum.com/t/routing-file-upload-put-vs-post-puzzle/182101 "2010-01-22T17:48:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pitosalas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a4c791/32.png) [@pitosalas](https://www.ruby-forum.com/u/pitosalas)\
**Post date:** [January 22, 2010, 5:48pm UTC](https://www.ruby-forum.com/t/routing-file-upload-put-vs-post-puzzle/182101/1 "2010-01-22T17:48:52Z")

</div>

I think I am doing something simply boneheaded but I don’t see it. I  
hope you are willing to take a look:

I am simply wanting to upload a file and hand the file in my controller  
to some code that will process it. It is not getting stored.

The UI is a “maintain” page with a file entry field in a form, and a  
button to import the file and some other maintenance tasks which are not  
relevant right now.

Here are snippets:

routes.rb:

map.maintain ‘/maintain/import\_file’, :controller =\> ‘maintain’,  
:action =\> ‘import\_file’, :conditions =\> { :method =\> :put }  
map.maintain ‘/maintain/export\_file’, :controller =\> ‘maintain’,  
:action =\> ‘export\_file’, :conditions =\> { :method =\> :put }  
map.maintain ‘/maintain/:action’, :controller =\> ‘maintain’

notes: I know this is too verbose, it’s been my attempt to trouble  
shoot. I don’t believe this should be a resource route given that its a  
maintenance page. But I could be wrong about that.

index.html.erb:

What would you like to maintain?

- \<% form\_tag :action =\> 'import\_file', :method =\> 'put', :multipart =\> true do %\> \<%= file\_field\_tag "importFile", :accept =\> "text/xml" %\>   
Import as: \<%= submit\_tag "XML file" %\> \<%= submit\_tag "YML file" %\> \<% end %\> 

notes: There are two buttons in this form, one to import it from an XML  
file and one from a YML file. Is that somehow making it sick?

maintain\_controller.rb:

def import\_file  
begin  
if params[:importFile].nil?  
flash[:error] = “Yes: Import failed because file was not  
specified.”  
redirect\_to :back  
[…] snip

Notes: when I break here, params[:importFile] is a text string with the  
file name, NOT a File:: object. Also the url looks like this:  
[http://localhost:3000/maintain/import\_file?method=put&multipart=true](http://localhost:3000/maintain/import_file?method=put&multipart=true)  
which is not what I expected.

Thanks for spending a few minutes with me on this, if possible!!

Pito S.
