# Edit uploaded file

**URL:** <https://www.ruby-forum.com/t/edit-uploaded-file/142260>\
**Category:** Rails\
**Created:** [July 5, 2008, 11:51am UTC](https://www.ruby-forum.com/t/edit-uploaded-file/142260 "2008-07-05T11:51:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaiganez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ec8ea/32.png) [@jaiganez](https://www.ruby-forum.com/u/jaiganez)\
**Post date:** [July 5, 2008, 11:51am UTC](https://www.ruby-forum.com/t/edit-uploaded-file/142260/1 "2008-07-05T11:51:22Z")

</div>

how to edit uploaded file ???pls help…

---

<div class="post-metadata">

**Author:** ![jaiganez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ec8ea/32.png) [@jaiganez](https://www.ruby-forum.com/u/jaiganez)\
**Post date:** [July 5, 2008, 11:53am UTC](https://www.ruby-forum.com/t/edit-uploaded-file/142260/2 "2008-07-05T11:53:46Z")

</div>

i need to update uploaded file or image from directory as well as from  
database …

---

<div class="post-metadata">

**Author:** ![jaiganez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ec8ea/32.png) [@jaiganez](https://www.ruby-forum.com/u/jaiganez)\
**Post date:** [July 6, 2008, 10:07pm UTC](https://www.ruby-forum.com/t/edit-uploaded-file/142260/3 "2008-07-06T22:07:02Z")

</div>

So let me make sure I understand:

1. you want to edit what about a document? Filename? Content-type?  
If you want to edit the file itself, I’d think you’d have to download  
it, edit it, and then reupload it.

2. When you say from directory as well as database, do you mean that  
you want to be able to edit a file saved in the filesystem of the  
server and a file saved as binary data in the database?

Give us a littl’ more to work with so we can help…

Ron

---

<div class="post-metadata">

**Author:** ![jaiganez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ec8ea/32.png) [@jaiganez](https://www.ruby-forum.com/u/jaiganez)\
**Post date:** [July 7, 2008, 6:02am UTC](https://www.ruby-forum.com/t/edit-uploaded-file/142260/4 "2008-07-07T06:02:49Z")

</div>

thank u for your kind rply…  
i ve uploaded file/image into database and folder named “data”… and i  
also able to update the uploaded files/images in database …but dont  
know how to …in folder “data”…

heres my controller file

def create  
@show =Show.new(params[:show])

```
@show.filename= params[:show]['filename'].original_filename
if @show.save
post = Show.save(params[:show])

```

redirect\_to :action =\> ‘list’  
end  
def update  
@show = Show.find(params[:id])

```
if @show.update_attributes(params[:show])

  flash[:notice] = 'Document was successfully updated.'
  redirect_to :action => 'list'
else
  render :action => 'edit'
end

```

end  
def edit  
@show=Show.find(params[:id])  
end

> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >

model.rb file…

def self.save(product)  
name =product[‘filename’].original\_filename  
path = File.join(“public/data”, name)  
File.open(path, “wb”) { |f| f.write(product[‘filename’].read) }  
end

> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >

new.rhtml…  
\<% form\_tag ({ :action =\> ‘create’ },  
{ :multipart =\> ‘true’ }) do%\>

Title: \<%=text\_field 'show','title'%\>

Mobile Type: \<%=text\_field 'show','mobilename'%\>

Price: \<%=text\_field 'show','price'%\>

Description: \<%=text\_field 'show','description'%\>

Image: \<%= file\_field 'show', 'filename' %\>

 \<%= submit\_tag "Send Attachment" %\> \<% end %\> \>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\> edit.rhtml....

\<% form\_tag (:action =\> ‘update’, :multipart =\> true, :id =\> @show )do%\>

Description  
\<%=text\_field 'show','title'%\>

\<%= file\_field 'show', 'filename' %\> \<%= @show.filename%\> \<%= hidden\_field( :hide, :value =\> @show.filename )%\> \<%= submit\_tag "Save changes" %\> \<%end %\> \<%= link\_to 'Back', {:action =\> 'list' } %\> \>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>
