# Newbie File\_Column and Console Question

**URL:** <https://www.ruby-forum.com/t/newbie-file-column-and-console-question/93568>\
**Category:** Rails\
**Created:** [April 4, 2006, 8:37pm UTC](https://www.ruby-forum.com/t/newbie-file-column-and-console-question/93568 "2006-04-04T20:37:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sshefer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d9b06d/32.png) [@sshefer](https://www.ruby-forum.com/u/sshefer)\
**Post date:** [April 4, 2006, 8:37pm UTC](https://www.ruby-forum.com/t/newbie-file-column-and-console-question/93568/1 "2006-04-04T20:37:12Z")

</div>

I recently got File\_Column installed and working and it is great, but  
now I find myself needing to resize all the images I already uploaded.

Through the web I found that the answer lies in going to the  
script/console and adding:

Attachment.find(:all).each do |a|  
a.asset = File.open(a.asset)  
a.save  
end

But what exactly do I do next, I tried running it with no success. How  
can I make it work?

Thanks!

---

<div class="post-metadata">

**Author:** ![sshefer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d9b06d/32.png) [@sshefer](https://www.ruby-forum.com/u/sshefer)\
**Post date:** [April 7, 2006, 4:00am UTC](https://www.ruby-forum.com/t/newbie-file-column-and-console-question/93568/2 "2006-04-07T04:00:56Z")

</div>

> end
> 
> But what exactly do I do next, I tried running it with no success. How  
> can I make it work?
> 
> Thanks!

Here’s some more information it it will help.

The model I have is for my Products, with image as the  
attribute for the file\_column file.

I went into the console, and selected all of my products  
that do not have a file name in the image field, so that  
I would only get the products with current images.

So with that I made a loop to go through each product:

> > for product in @products  
> > product.image = File.open(product.image)  
> > product.save  
> > end

Now the loop works, I get no errors, but every file is  
loaded into the tmp folder!

After sorting through the returned array I noticed:  
#\<Product:0x2503acc @errors=#\<ActiveRecord::Errors:0x2476500  
@errors={“image”=\>[“invalid image”]},

Can anyone guide me on the next step? I’ve searched everywhere  
but cant seem to find a solution!

Thanks

---

<div class="post-metadata">

**Author:** ![sshefer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d9b06d/32.png) [@sshefer](https://www.ruby-forum.com/u/sshefer)\
**Post date:** [April 11, 2006, 3:38am UTC](https://www.ruby-forum.com/t/newbie-file-column-and-console-question/93568/3 "2006-04-11T03:38:59Z")

</div>

sshefer \<sshefer@…\> writes:

> > I recently got File\_Column installed and working and it is great, but  
> > now I find myself needing to resize all the images I already uploaded.
> 
> I went into the console, and selected all of my products  
> that do not have a file name in the image field, so that  
> I would only get the products with current images. But it doesn’t seem  
> to create the new version, just load it into tmp dir.

Can anyone else help?

I’ve searched every conceivable place for it with no luck, is this even  
possible? I’d like to know and add to the File Column HowTwo, as this  
seems to  
be a common question with no replies!

Anyone? Any help/guidance would be appreciated.

---

<div class="post-metadata">

**Author:** ![sshefer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d9b06d/32.png) [@sshefer](https://www.ruby-forum.com/u/sshefer)\
**Post date:** [April 11, 2006, 3:50am UTC](https://www.ruby-forum.com/t/newbie-file-column-and-console-question/93568/4 "2006-04-11T03:50:35Z")

</div>

shai shefer wrote:

> sshefer \<sshefer@…\> writes:
> 
> > > I recently got File\_Column installed and working and it is great, but  
> > > now I find myself needing to resize all the images I already uploaded.
> > 
> > I went into the console, and selected all of my products  
> > that do not have a file name in the image field, so that  
> > I would only get the products with current images. But it doesn’t seem  
> > to create the new version, just load it into tmp dir.
> 
> Can anyone else help?
> 
> I’ve searched every conceivable place for it with no luck, is this even  
> possible? I’d like to know and add to the File Column HowTwo, as this  
> seems to  
> be a common question with no replies!
> 
> Anyone? Any help/guidance would be appreciated.

Shai,

I believe that if you look at the File\_Column docs it will tell you that  
File\_Column works with ImageMagick (on Linux) in order to resize images  
on upload. You can even create multiple versions of the same file. I  
hope this helps.

Good luck,

Rob D.

---

<div class="post-metadata">

**Author:** ![sshefer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d9b06d/32.png) [@sshefer](https://www.ruby-forum.com/u/sshefer)\
**Post date:** [April 11, 2006, 4:15am UTC](https://www.ruby-forum.com/t/newbie-file-column-and-console-question/93568/5 "2006-04-11T04:15:34Z")

</div>

Thanks for the reply…

I looked into doing ImageMagick and running it through the console, but  
was  
wondering if there wasn’t a simpler, more sophisticated manner of  
updating  
the existing image tree with the new versions.

Is there no way to tie in the new versions set in the Model when opening  
an  
image and saving it?

## I would think this is a common problem, did no one else need to add/change image sizes?

View this message in context:  
[http://www.nabble.com/Newbie-File\_Column-and-Console-Question.-t1394748.html#a3853979](http://www.nabble.com/Newbie-File_Column-and-Console-Question.-t1394748.html#a3853979)  
Sent from the RubyOnRails Users forum at [Nabble.com](http://Nabble.com).
