# Basic File Question

**URL:** <https://www.ruby-forum.com/t/basic-file-question/140090>\
**Category:** Rails\
**Created:** [June 10, 2008, 7:08pm UTC](https://www.ruby-forum.com/t/basic-file-question/140090 "2008-06-10T19:08:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jorg\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/76d3ee/32.png) [@Jorg\_L](https://www.ruby-forum.com/u/Jorg_L)\
**Post date:** [June 10, 2008, 7:08pm UTC](https://www.ruby-forum.com/t/basic-file-question/140090/1 "2008-06-10T19:08:20Z")

</div>

I’m a data person and some of the basics on the front end seem to  
escape me. I am merely trying to upload a file to the backend.  
Everything works except that what is uploaded is not the file but the  
reference to the file, i.e. #\<File:0x57d79b8\>

It’s got to be a simple thing I am missing…

This is the form

\<% form\_for(@workstmt,:url=\>{:action=\>‘create’},  
:html =\> {:multipart=\>true}) do |f| %\>

**Project name**  
 \<%= f.text\_field :project\_name %\>

**File name**  
 \<%= f.text\_field :file\_name %\>

**Sow**  
 \<%= f.text\_field :sow\_id %\>

**Workstmt**  
 \<%= f.file\_field :workstmt %\>

\<%= f.submit "Create" %\>

\<% end %\>

and the controller snippet is the default from the scaffold

def create  
@workstmt = Workstmt.new(params[:workstmt])  
respond\_to do |format|  
if @workstmt.save  
flash[:notice] = ‘Workstmt was successfully created.’  
format.html { redirect\_to(@workstmt) }  
format.xml { render :xml =\> @workstmt, :status  
=\> :created, :location =\> @workstmt }  
else  
format.html { render :action =\> “new” }  
format.xml { render :xml =\> @workstmt.errors, :status  
=\> :unprocessable\_entity }  
end  
end

---

<div class="post-metadata">

**Author:** ![Jorg\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/76d3ee/32.png) [@Jorg\_L](https://www.ruby-forum.com/u/Jorg_L)\
**Post date:** [June 11, 2008, 8:55pm UTC](https://www.ruby-forum.com/t/basic-file-question/140090/2 "2008-06-11T20:55:01Z")

</div>

This is the controller code that will work (with workstmt\_file) being  
the name of the file\_field comng from the form

@workstmt = Workstmt.new  
@workstmt.file\_name = params[:workstmt]  
[:workstmt\_file].original\_filename  
@workstmt.content\_type = params[:workstmt]  
[:workstmt\_file].content\_type  
@workstmt.workstmt = params[:workstmt][:workstmt\_file].read
