# Undefined method \`read' for

**URL:** <https://rubytalk.org/t/undefined-method-read-for/25301>\
**Category:** ruby-talk\
**Created:** [1 March 2006 01:57 UTC](https://rubytalk.org/t/undefined-method-read-for/25301 "2006-03-01T01:57:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![misiek](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@misiek](https://rubytalk.org/u/misiek)\
**Post date:** [1 March 2006 01:57 UTC](https://rubytalk.org/t/undefined-method-read-for/25301/1 "2006-03-01T01:57:58Z")

</div>

I got an error undefined method `read' for, why ?

this is what I am doing

@user = "new\_image"  
File.open("#{RAILS\_ROOT}/public/images/#{@user}.jpg", "wb") do |f|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f.write(@params['image\_file'].read)  
end

thanks

---

<div class="post-metadata">

**Author:** ![misiek](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@misiek](https://rubytalk.org/u/misiek)\
**Post date:** [1 March 2006 01:57 UTC](https://rubytalk.org/t/undefined-method-read-for/25301/2 "2006-03-01T01:57:47Z")

</div>

> I'm guessing that whatever @params['image\_file'] is doesn't have a read method.  
> If it's just a filename, for instance, you have to open it and call read  
> on the File object, e.g.
> 
> File.open("#{RAILS\_ROOT}/public/images/#{@user}.jpg", "wb") do \>f\>  
> &nbsp;&nbsp;f.write(File.open(@params['image\_file']).read)  
> end

works better but still have error

can't convert Array into String

---

<div class="post-metadata">

**Author:** ![Mark\_J\_Reed1](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@Mark\_J\_Reed1](https://rubytalk.org/u/Mark_J_Reed1)\
**Post date:** [1 March 2006 01:57 UTC](https://rubytalk.org/t/undefined-method-read-for/25301/3 "2006-03-01T01:57:51Z")

</div>

misiek \<michaelaugustyniak@gazeta.pl\> writes:

> I got an error undefined method `read' for, why ?

> this is what I am doing

> @user = "new\_image"  
> File.open("#{RAILS\_ROOT}/public/images/#{@user}.jpg", "wb") do |f|  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f.write(@params['image\_file'].read)  
> end

I'm guessing that whatever @params['image\_file'] is doesn't have a read method.  
If it's just a filename, for instance, you have to open it and call read  
on the File object, e.g.

File.open("#{RAILS\_ROOT}/public/images/#{@user}.jpg", "wb") do  
&nbsp;&nbsp;\>f\>  
&nbsp;&nbsp;f.write(File.open(@params['image\_file']).read)  
end
