# Pb upload in Rails

**URL:** <https://www.ruby-forum.com/t/pb-upload-in-rails/123427>\
**Category:** Rails\
**Created:** [December 17, 2007, 4:49pm UTC](https://www.ruby-forum.com/t/pb-upload-in-rails/123427 "2007-12-17T16:49:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bardachrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ac91a4/32.png) [@bardachrails](https://www.ruby-forum.com/u/bardachrails)\
**Post date:** [December 17, 2007, 4:49pm UTC](https://www.ruby-forum.com/t/pb-upload-in-rails/123427/1 "2007-12-17T16:49:20Z")

</div>

Hello everybody,

I develope my own application with RoR.

I use the code after to upload the files to a directory in the public  
folder of my app, and store the URI of the file in the database as a  
string,.

But in my db I find this:

— !ruby/object:File {}

Thinks for any help?

Bardach

* * *

Indications:

> Controller

def create  
@document = Document.new(@params[‘document’])  
@domaines = Domaine.find\_all  
if @document.save  
flash[:notice] = ‘Le document Ã Ã©tÃ© crÃ©er avec succÃ¨s.’  
post = DataFile.save(@params[“document”])  
redirect\_to :controller =\> ‘document’, :action =\> ‘list’  
else  
render :action =\> ‘new’  
end  
end

> Model

def self.save(upload)  
name = upload[‘file\_url’].original\_filename  
directory = “public/Documents”

# create the file path

path = File.join(directory, name)

# write the file

File.open(path, “wb”) { |f| f.write(upload[‘file\_url’].read) }  
end  
NB : “file\_url” is a field of my table “documents” where i wan’t store  
the url of uploaded file.
