# Upload File

**URL:** <https://www.ruby-forum.com/t/upload-file/99925>\
**Category:** Rails\
**Created:** [July 26, 2006, 7:32am UTC](https://www.ruby-forum.com/t/upload-file/99925 "2006-07-26T07:32:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fird](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/4af34b/32.png) [@fird](https://www.ruby-forum.com/u/fird)\
**Post date:** [July 26, 2006, 7:32am UTC](https://www.ruby-forum.com/t/upload-file/99925/1 "2006-07-26T07:32:56Z")

</div>

I got this error:

NoMethodError in PictureController#new

You have a nil object when you didn’t expect it!  
The error occured while evaluating nil.uploaded\_file=

and the line code is here:

@picture.uploaded\_file = @params[‘picture\_file’]

---

<div class="post-metadata">

**Author:** ![fird](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/4af34b/32.png) [@fird](https://www.ruby-forum.com/u/fird)\
**Post date:** [July 26, 2006, 8:20am UTC](https://www.ruby-forum.com/t/upload-file/99925/2 "2006-07-26T08:20:34Z")

</div>

Can you show a little more code so we can see what’s causing the error?  
Are  
you using file\_column? Where did you initialize @picture, etc.

Fird Abrar wrote:

> @picture.uploaded\_file = @params[‘picture\_file’]

–  
View this message in context:  
[http://www.nabble.com/Upload-File-tf2002132.html#a5498282](http://www.nabble.com/Upload-File-tf2002132.html#a5498282)  
Sent from the RubyOnRails Users forum at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![fird](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/4af34b/32.png) [@fird](https://www.ruby-forum.com/u/fird)\
**Post date:** [July 26, 2006, 8:32am UTC](https://www.ruby-forum.com/t/upload-file/99925/3 "2006-07-26T08:32:53Z")

</div>

class PictureController \< ApplicationController  
def new  
picture = Picture.new()  
@picture.uploaded\_file = @params[‘picture\_file’]  
@picture.save  
redirect\_to :action =\> ‘index’  
end  
end

Steve R. wrote:

> Can you show a little more code so we can see what’s causing the error?  
> Are  
> you using file\_column? Where did you initialize @picture, etc.

---

<div class="post-metadata">

**Author:** ![fird](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/4af34b/32.png) [@fird](https://www.ruby-forum.com/u/fird)\
**Post date:** [July 26, 2006, 10:17am UTC](https://www.ruby-forum.com/t/upload-file/99925/4 "2006-07-26T10:17:47Z")

</div>

Hello,

You forgot the @ sign in the line where you create a new picture object.

Greetings, Joran.

Fird Abrar wrote:

> class PictureController \< ApplicationController  
> def new  
> picture = Picture.new()  
> @picture.uploaded\_file = @params[‘picture\_file’]  
> @picture.save  
> redirect\_to :action =\> ‘index’  
> end  
> end
> 
> Steve R. wrote:
> 
> > Can you show a little more code so we can see what’s causing the error?  
> > Are  
> > you using file\_column? Where did you initialize @picture, etc.

---

<div class="post-metadata">

**Author:** ![fird](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/4af34b/32.png) [@fird](https://www.ruby-forum.com/u/fird)\
**Post date:** [July 26, 2006, 11:57pm UTC](https://www.ruby-forum.com/t/upload-file/99925/5 "2006-07-26T23:57:54Z")

</div>

You left the at-sign off picture when you initialized it. s/b:

@picture = Picture.new

Fird Abrar wrote:

> class PictureController \< ApplicationController  
> def new  
> picture = Picture.new()  
> @picture.uploaded\_file = @params[‘picture\_file’]  
> @picture.save  
> redirect\_to :action =\> ‘index’  
> end  
> end

–  
View this message in context:  
[http://www.nabble.com/Upload-File-tf2002132.html#a5505766](http://www.nabble.com/Upload-File-tf2002132.html#a5505766)  
Sent from the RubyOnRails Users forum at [Nabble.com](http://Nabble.com).
