Upload in Rails

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 database, I find this:

— !ruby/object:File {}

or some time:

!ruby/object:StringIO{}

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs