# File Uploding coding problems

**URL:** <https://www.ruby-forum.com/t/file-uploding-coding-problems/120060>\
**Category:** Rails\
**Created:** [November 13, 2007, 12:38pm UTC](https://www.ruby-forum.com/t/file-uploding-coding-problems/120060 "2007-11-13T12:38:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed8c4c/32.png) [@nad](https://www.ruby-forum.com/u/nad)\
**Post date:** [November 13, 2007, 12:38pm UTC](https://www.ruby-forum.com/t/file-uploding-coding-problems/120060/1 "2007-11-13T12:38:39Z")

</div>

I used the following codes found in the net to use to write a file to  
upload the files. down are the codes i have used. but still i did not  
able to get the correct coding. so if somebody know where i have gone  
wrong pls reply.

###################### IN the View #############################3

**Name:**  
 \<%= text\_field "person", "name" %\>

**Picture:**

#################The controller:##########################

class AddressbookController \< ApplicationController  
def new  
# not really needed since the template doesn’t rely on any data  
end

def create  
post = Post.save(@params[“person”])  
# Doesn’t this mean post is a File object?  
# post.id is a bad idea in this case…

```
redirect_to :action => "show", :id => post.id

```

end  
end

######### the model ###################

class Post \< ActiveRecord::Base  
def self.save(person)  
f = File.new(“pictures/#{person[‘name’]}/picture.jpg”, “wb”)  
f.write params[:picture].read  
f.close  
end

in the uploading it gives a error like this

undefined local variable or method `params’ for Post:Class

so i did some modification as  
f.write params[:picture].read  
line to  
f.write (@params[:picture].read)

so the code woke properly, but still it gives a error saying

You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occurred while evaluating nil.[]

SO IF SOMEBODY KNOW HOW TO OVER COME THIS PROBLEM PLS REPLY

---

<div class="post-metadata">

**Author:** ![nad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed8c4c/32.png) [@nad](https://www.ruby-forum.com/u/nad)\
**Post date:** [November 13, 2007, 12:43pm UTC](https://www.ruby-forum.com/t/file-uploding-coding-problems/120060/2 "2007-11-13T12:43:48Z")

</div>

> undefined local variable or method `params’ for Post:Class

The message is pretty clear: params doesn’t exist here. It only exists  
inside an instance of controller. You need to pass params through to  
the save method (which you’re already doing, but not using it for some  
reason.).

Fred

---

<div class="post-metadata">

**Author:** ![nad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed8c4c/32.png) [@nad](https://www.ruby-forum.com/u/nad)\
**Post date:** [November 13, 2007, 1:03pm UTC](https://www.ruby-forum.com/t/file-uploding-coding-problems/120060/3 "2007-11-13T13:03:34Z")

</div>

Frederick C. wrote:

> > undefined local variable or method `params’ for Post:Class
> 
> The message is pretty clear: params doesn’t exist here. It only exists  
> inside an instance of controller. You need to pass params through to  
> the save method (which you’re already doing, but not using it for some  
> reason.).
> 
> Fred

thanks a lot man. now i saw where i had done the coding wrongly. thanks  
a lot for showing the mistake i was doing.
