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.
8520bd1ba7ef07ee81484fbda8ef4cbb?d=identicon&s=25 Henrik =?iso-8859-1?Q?Orm=E5sen?= (Guest)
on 2006-06-04 10: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
E46fdf78038eebf8342ca5acb9a26a5c?d=identicon&s=25 Dmitry V. Sabanin (Guest)
on 2006-06-04 11: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
8520bd1ba7ef07ee81484fbda8ef4cbb?d=identicon&s=25 Henrik =?iso-8859-1?Q?Orm=E5sen?= (Guest)
on 2006-06-05 10: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
829d692dfbd5764f0543fe18be9b964a?d=identicon&s=25 ratchetcat (Guest)
on 2006-06-05 14: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?
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2006-06-05 16: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.