[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

undefined method `read' for

misiek

2/28/2006 8:55:00 PM

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|
f.write(@params['image_file'].read)
end

thanks
2 Answers

Mark J. Reed

2/28/2006 9:01:00 PM

0

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|
> 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
|f|
f.write(File.open(@params['image_file']).read)
end

misiek

2/28/2006 9:07:00 PM

0


>
> 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|
> f.write(File.open(@params['image_file']).read)
> end

works better but still have error

can't convert Array into String