Forum: Ruby undefined method `read' for

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
misiek (Guest)
on 2006-03-01 04:08
(Received via mailing list)
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
Mark J.Reed (Guest)
on 2006-08-15 16:09
(Received via mailing list)
misiek <removed_email_address@domain.invalid> 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 (Guest)
on 2006-08-15 16:21
(Received via mailing list)
>
> 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
This topic is locked and can not be replied to.