# Error in uploading file(help me urgnt)

**URL:** <https://www.ruby-forum.com/t/error-in-uploading-file-help-me-urgnt/185910>\
**Category:** Rails\
**Created:** [March 29, 2010, 6:41am UTC](https://www.ruby-forum.com/t/error-in-uploading-file-help-me-urgnt/185910 "2010-03-29T06:41:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [March 29, 2010, 6:41am UTC](https://www.ruby-forum.com/t/error-in-uploading-file-help-me-urgnt/185910/1 "2010-03-29T06:41:04Z")

</div>

when i tried to crate an upload file application in rails i am getting  
error like this

Template is missing

Missing template app\views\upload\uploadfile.html.erb in view path  
app/views

this is ma model

class DataFile \< ActiveRecord::Base  
def self.save(upload)  
name = upload[‘datafile’].original\_filename  
directory = “public/data”  
# create the file path  
path = File.join(directory, name)  
# write the file  
File.open(path, “wb”) { |f| f.write(upload[‘datafile’].read) }  
end  
end

this is ma view file

# File Upload
\<%= start\_form\_tag ({:action =\> 'uploadFile'}, :multipart =\> true) %\>

Select File : \<%= file\_field 'upload', 'datafile' %\>

\<%= submit\_tag "Upload" %\> \<%= end\_form\_tag %\>

This is ma controller

class UploadController \< ApplicationController  
def index  
puts ‘hiiiiiiiiiii’  
render :file =\> ‘app\views\upload\uploadfile.html.erb’  
puts ‘hiiiiiiiiiii2’  
end  
def uploadFile  
puts ‘hiiiiiiiiiii3’  
post = DataFile.save(params[:upload])  
render :text =\> “File has been uploaded successfully”  
end  
end

---

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [March 29, 2010, 8:20am UTC](https://www.ruby-forum.com/t/error-in-uploading-file-help-me-urgnt/185910/2 "2010-03-29T08:20:25Z")

</div>

I think use _render :file =\> ‘uploadfile.html.erb’_, as rails would look  
for  
the template in your view directory, which is “app/views”,

and if you use render :file =\> ‘controller/uploadfile.html.erb’, it will  
look for the template in “app/views/controller/uploadfile.html.erb”, or  
rails always

assume you have already put your template in the controller’s according  
view  
folder

---

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [March 29, 2010, 8:26am UTC](https://www.ruby-forum.com/t/error-in-uploading-file-help-me-urgnt/185910/3 "2010-03-29T08:26:18Z")

</div>

Yong Gu wrote:

> I think use _render :file =\> ‘uploadfile.html.erb’_, as rails would look  
> for  
> the template in your view directory, which is “app/views”,
> 
> and if you use render :file =\> ‘controller/uploadfile.html.erb’, it will  
> look for the template in “app/views/controller/uploadfile.html.erb”, or  
> rails always
> 
> assume you have already put your template in the controller’s according  
> view  
> folder

wheen i did that i am getting the error like this

hiiiiiiiiiii3  
SQL (0.5ms) SET client\_min\_messages TO ‘panic’  
SQL (0.5ms) SET client\_min\_messages TO ‘notice’  
SQL (0.6ms) SET client\_encoding TO ‘unicode’

Processing UploadController#uploadFile (for 127.0.0.1 at 2010-03-29  
11:47:28) [POST]  
Parameters: {“commit”=\>“Upload”,  
“authenticity\_token”=\>“g1vUQZ7QAh7FjfusjbJuh7EBO4UVVFInaYsxzCMK91I=”,  
“date\_file”=\>{“upload”=\>#\<File:/tmp/RackMultipart.3648.0\>}}

NoMethodError (You have a nil object when you didn’t expect it!  
You might have expected an instance of ActiveRecord::Base.  
The error occurred while evaluating nil.[]):

---

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [March 29, 2010, 8:33am UTC](https://www.ruby-forum.com/t/error-in-uploading-file-help-me-urgnt/185910/4 "2010-03-29T08:33:54Z")

</div>

Did you add uploadFile to route.rb?

And i think you’d better follow rails’ convention, instead of writing  
code  
as like using some other frameworks

---

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [March 29, 2010, 9:00am UTC](https://www.ruby-forum.com/t/error-in-uploading-file-help-me-urgnt/185910/5 "2010-03-29T09:00:49Z")

</div>

hi yong  
i got the same proble and solved it ,

you can use in form tag uploadfile instead of uploadFile

and in render file : use #"{root\_url}/app/view/–path"

hope you will solve it …  
thanks

rahul
