# Need immediate help on file uploading

**URL:** <https://www.ruby-forum.com/t/need-immediate-help-on-file-uploading/89561>\
**Category:** Rails\
**Created:** [March 21, 2007, 10:00am UTC](https://www.ruby-forum.com/t/need-immediate-help-on-file-uploading/89561 "2007-03-21T10:00:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kushan\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/d2c977/32.png) [@Kushan\_J](https://www.ruby-forum.com/u/Kushan_J)\
**Post date:** [March 21, 2007, 10:00am UTC](https://www.ruby-forum.com/t/need-immediate-help-on-file-uploading/89561/1 "2007-03-21T10:00:45Z")

</div>

Hi Guys

i’ll give you my model, controller(not entire one) and view that i  
already  
have

model

class MetroUpload \< ActiveRecord::Base

def self.save(metro\_upload)  
File.open(“Metro\_SQL/#{metro\_upload[‘name’]}/metro.sql”, “w”) {  
|f|  
f.read(metro\_upload[‘sql\_file’].rewind)  
f.write(metro\_upload[‘sql\_file’].read)  
}

end

end

controller

def create

```
if @post = MetroUpload.save(@params["metro_upload"])
breakpoint
  flash[:notice] = 'Metro Upload was successfully created.'
  redirect_to :action => 'list'
else
  render :action => 'new'
end

```

end

virew

# New Metro file upload

\<%= form\_remote\_tag (:update =\>“update\_div”,:multipart =\> true,  
:url =\>{:action =\> ‘create’}) %\>

\<%= render :partial =\> ‘form’ %\> # see the partial  
\<%= submit\_tag “Upload it” %\>  
\<%= end\_form\_tag %\>

\<%= link\_to ‘Back’, :controller =\> ‘badger\_cab\_erp\_admin’ %\>

\_form.rhtml # my partial

\<%= error\_messages\_for ‘metro\_upload’ %\>

Attach your sql file

my problem is i can upload a file in this way, but there is nothing in  
my  
file (there is nothing in its contents)

only file will be created with the given name - zero length file

Plz any one can tell me how to fix this ( i want to upload the file with  
its  
contents)

Thx  
Kushan

---

<div class="post-metadata">

**Author:** ![Kushan\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/d2c977/32.png) [@Kushan\_J](https://www.ruby-forum.com/u/Kushan_J)\
**Post date:** [March 21, 2007, 10:03am UTC](https://www.ruby-forum.com/t/need-immediate-help-on-file-uploading/89561/2 "2007-03-21T10:03:45Z")

</div>

Kushan J. schreef:

> Hi Guys
> 
> \<%= form\_remote\_tag (:update =\>“update\_div”,:multipart =\> true,  
> :url =\>{:action =\> ‘create’}) %\>  
> As fas as I know, uploading files doesn’t work with AJAXified forms.  
> Try this:

\<%= start\_form\_tag({:action =\> ‘create’}, {:multipart =\> true }) %\>
