# Uploading file inruby on rails

**URL:** <https://www.ruby-forum.com/t/uploading-file-inruby-on-rails/144414>\
**Category:** Rails\
**Created:** [July 29, 2008, 1:44pm UTC](https://www.ruby-forum.com/t/uploading-file-inruby-on-rails/144414 "2008-07-29T13:44:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sujith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/77aa72/32.png) [@sujith](https://www.ruby-forum.com/u/sujith)\
**Post date:** [July 29, 2008, 1:44pm UTC](https://www.ruby-forum.com/t/uploading-file-inruby-on-rails/144414/1 "2008-07-29T13:44:43Z")

</div>

I am uploading on html file and saving in public folder for this i am  
writing this code  
def self.save(upload)  
name = upload[‘datafile’].original\_filename  
directory = “public/uploads”  
path = File.join(directory, name)  
str ="Hi9 How r u "  
File.open(path, “a”) { |f| f.puts str }  
return name  
end  
what this is doing means i am inserting str into that file  
it is over writing the existing file content  
i dont want to overwrite , i want to add in the last line of the  
document  
please help me on this

---

<div class="post-metadata">

**Author:** ![sujith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/77aa72/32.png) [@sujith](https://www.ruby-forum.com/u/sujith)\
**Post date:** [July 29, 2008, 4:27pm UTC](https://www.ruby-forum.com/t/uploading-file-inruby-on-rails/144414/2 "2008-07-29T16:27:17Z")

</div>

Sujith Gangaraju wrote:

> I am uploading on html file and saving in public folder for this i am  
> writing this code  
> def self.save(upload)  
> name = upload[‘datafile’].original\_filename  
> directory = “public/uploads”  
> path = File.join(directory, name)  
> str ="Hi9 How r u "  
> File.open(path, “a”) { |f| f.puts str }  
> return name  
> end  
> what this is doing means i am inserting str into that file  
> it is over writing the existing file content  
> i dont want to overwrite , i want to add in the last line of the  
> document  
> please help me on this

Try once more sujith…  
Come onnnnnn…  
you can do ittttttt…
