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.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---