# Fil from filsystem -\> db

**URL:** <https://www.ruby-forum.com/t/fil-from-filsystem-db/62411>\
**Category:** Rails\
**Created:** [June 4, 2006, 10:58am UTC](https://www.ruby-forum.com/t/fil-from-filsystem-db/62411 "2006-06-04T10:58:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Henrik\_SSiso-8859-1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/3be4f8/32.png) [@Henrik\_SSiso-8859-1](https://www.ruby-forum.com/u/Henrik_SSiso-8859-1)\
**Post date:** [June 4, 2006, 10:58am UTC](https://www.ruby-forum.com/t/fil-from-filsystem-db/62411/1 "2006-06-04T10:58:30Z")

</div>

Since Ajax doesn’t support file uploads, I’m using “IFRAME remoting  
made easy” ([http://sean.treadway.info/](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

---

<div class="post-metadata">

**Author:** ![Henrik\_SSiso-8859-1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/3be4f8/32.png) [@Henrik\_SSiso-8859-1](https://www.ruby-forum.com/u/Henrik_SSiso-8859-1)\
**Post date:** [June 4, 2006, 11:44am UTC](https://www.ruby-forum.com/t/fil-from-filsystem-db/62411/2 "2006-06-04T11:44:09Z")

</div>

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://futuretrack5.com) | [http://sabanin.ru/en](http://sabanin.ru/en)

---

<div class="post-metadata">

**Author:** ![Henrik\_SSiso-8859-1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/3be4f8/32.png) [@Henrik\_SSiso-8859-1](https://www.ruby-forum.com/u/Henrik_SSiso-8859-1)\
**Post date:** [June 5, 2006, 10:19am UTC](https://www.ruby-forum.com/t/fil-from-filsystem-db/62411/3 "2006-06-05T10:19:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Henrik\_SSiso-8859-1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/3be4f8/32.png) [@Henrik\_SSiso-8859-1](https://www.ruby-forum.com/u/Henrik_SSiso-8859-1)\
**Post date:** [June 5, 2006, 4:04pm UTC](https://www.ruby-forum.com/t/fil-from-filsystem-db/62411/4 "2006-06-05T16:04:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Henrik\_SSiso-8859-1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/3be4f8/32.png) [@Henrik\_SSiso-8859-1](https://www.ruby-forum.com/u/Henrik_SSiso-8859-1)\
**Post date:** [June 5, 2006, 2:41pm UTC](https://www.ruby-forum.com/t/fil-from-filsystem-db/62411/5 "2006-06-05T14:41:01Z")

</div>

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?
