Forum: Ruby on Rails Fil from filsystem -> db

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.
Henrik =?iso-8859-1?Q?Orm=E5sen?= (Guest)
on 2006-06-04 12:58
(Received via mailing list)
Since Ajax doesn't support file uploads, I'm using "IFRAME remoting
made easy" (http://sean.treadway.info/). I'm saving a file to the
filesystem, and then trying to put it in to the database when I do the
final submit with ajax. I thought picking the file up and putting it
in the db would be as easy as having:
"@image.data = IO.read("path_to_file") in the create method in the
controller. But I get: "undefined method `read' for #"

What's the right way of doing this?

- Henrik
Dmitry V. Sabanin (Guest)
on 2006-06-04 13:44
(Received via mailing list)
On Jun 4, 2006, at 4:57 PM, Henrik Ormåsen wrote:
> "@image.data = IO.read("path_to_file") in the create method in the
> controller. But I get: "undefined method `read' for #"
>
> What's the right way of doing this?
Try IO.readlines("path_to_file").join instead of IO.read

HTH,
--
Dmitry Sabanin
http://futuretrack5.com | http://sabanin.ru/en
Henrik =?iso-8859-1?Q?Orm=E5sen?= (Guest)
on 2006-06-05 12:19
(Received via mailing list)
Sun, 04 Jun 2006, Dmitry V. Sabanin skrev:

>
> On Jun 4, 2006, at 4:57 PM, Henrik Ormåsen wrote:
> >"@image.data = IO.read("path_to_file") in the create method in the
> >controller. But I get: "undefined method `read' for #"
> >
> >What's the right way of doing this?
> Try IO.readlines("path_to_file").join instead of IO.read

That didn't help. I still get "undefined method `read' for #" :-(.

- Henrik
ratchetcat (Guest)
on 2006-06-05 16:41
Henrik =?iso-8859-1?Q?Orm=E5sen?= wrote:
> Sun, 04 Jun 2006, Dmitry V. Sabanin skrev:
>
>>
>> On Jun 4, 2006, at 4:57 PM, Henrik Orm�sen wrote:
>> >"@image.data = IO.read("path_to_file") in the create method in the
>> >controller. But I get: "undefined method `read' for #"
>> >
>> >What's the right way of doing this?
>> Try IO.readlines("path_to_file").join instead of IO.read
>
> That didn't help. I still get "undefined method `read' for #" :-(.
>
> - Henrik

That's very odd. Ruby doesn't think you're using the standard IO class.
Are you certain you haven't redefined that class somewhere else in your
code? Alternatively...try reinstalling ruby?
Bill W. (Guest)
on 2006-06-05 18:04
(Received via mailing list)
Hi Henrik,

>>> On Jun 4, 2006, at 4:57 PM, Henrik Orm�sen wrote:
>>> >"@image.data = IO.read("path_to_file") in the create method in the
>>> >controller. But I get: "undefined method `read' for #"
>>> >
>>> >What's the right way of doing this?
>>> Try IO.readlines("path_to_file").join instead of IO.read
>>
>> That didn't help. I still get "undefined method `read' for #" :-(.

If you changed a line containing 'IO.read' to 'IO.readlines' and you're
still getting a message that says, in part, "undefined method 'read' for
#"
then your code is not failing at that line.  If it were, you would be
getting a message that says "undefined method 'readlines' for #"

If you look more closely at the error message RoR is giving you, it
tells
you the controller | view | model / method / line number that caused the
error.  It's not all in one line, but it's all there.

hth,
Bill
This topic is locked and can not be replied to.