# More flexible file column?

**URL:** <https://www.ruby-forum.com/t/more-flexible-file-column/62221>\
**Category:** Rails\
**Created:** [June 1, 2006, 5:45pm UTC](https://www.ruby-forum.com/t/more-flexible-file-column/62221 "2006-06-01T17:45:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![DJ\_Tequila](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@DJ\_Tequila](https://www.ruby-forum.com/u/DJ_Tequila)\
**Post date:** [June 1, 2006, 5:45pm UTC](https://www.ruby-forum.com/t/more-flexible-file-column/62221/1 "2006-06-01T17:45:37Z")

</div>

The file column plug-in is great, but there is a problem with it. Well,  
two… But the other is well documented now. :^)

Consider a time when you’ve created a CMS for a client and it’s been in  
use for over a year. Say 1500+ images have been uploaded so far. Now the  
client comes back with a simple request… ‘Can you change the thumbnail  
size to 80/90, rather than 70/70? It shouldn’t take you more than half a  
day…’  
‘No problem!’ you say, ‘I’ll just change the CSS _here_, and the article  
model _here_ and… Oh.’ Broken images all over the place. No images at  
all if you use Firefox.

It wasn’t quite 1500 images, but I ended up writing a script to  
systematically go through each image in the database and resize it to  
order… File column helpfully handles removing the old sizes for you.

This is all a but un-rails-like though. I’d expect the plugin to  
automatically realise that the resized image is missing and create it on  
the fly. It has all the tools and data to do so, and the perfomance hit  
will only be felt once, by the first user who encounters the image. I’d  
take that to be an acceptable compromise.

I have, in fact, written such code quite successfully in PHP. However,  
I’m new to Ruby and not completely comfortable with it yet. Has anyone  
done it themselves? If not, has anyone looked into the File Column code  
enough to give me a few pointers? Obviously if I get it working I’ll  
release it back to the Rails community…

Or does anyone think I’ve gone mad and should stick to scripts? ;^)

---

<div class="post-metadata">

**Author:** ![DJ\_Tequila](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@DJ\_Tequila](https://www.ruby-forum.com/u/DJ_Tequila)\
**Post date:** [June 1, 2006, 6:08pm UTC](https://www.ruby-forum.com/t/more-flexible-file-column/62221/2 "2006-06-01T18:08:17Z")

</div>

I thought file column made this sort of thing really easy.

|file\_column :image, :magick =\> { :geometry =\> “800x600\>” }

see: [http://wiki.rubyonrails.org/rails/pages/HowToUseFileColumn](http://wiki.rubyonrails.org/rails/pages/HowToUseFileColumn)  
|

---

<div class="post-metadata">

**Author:** ![DJ\_Tequila](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@DJ\_Tequila](https://www.ruby-forum.com/u/DJ_Tequila)\
**Post date:** [June 1, 2006, 6:33pm UTC](https://www.ruby-forum.com/t/more-flexible-file-column/62221/3 "2006-06-01T18:33:24Z")

</div>

2006/6/1, DJ Tequila [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I have, in fact, written such code quite successfully in PHP. However,  
> I’m new to Ruby and not completely comfortable with it yet. Has anyone  
> done it themselves? If not, has anyone looked into the File Column code  
> enough to give me a few pointers? Obviously if I get it working I’ll  
> release it back to the Rails community…
> 
> Or does anyone think I’ve gone mad and should stick to scripts? ;^)

this is how i did it (all images were jpgs):

lib/image\_resize.rb:

require “action\_controller/test\_process”

Image.find\_all.each do |i|  
i.path=ActionController::TestUploadedFile.new(i.path, “image/jpeg”)  
i.save  
end

start:

script/runner “load(‘image\_resize.rb’)”

–robert

---

<div class="post-metadata">

**Author:** ![DJ\_Tequila](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@DJ\_Tequila](https://www.ruby-forum.com/u/DJ_Tequila)\
**Post date:** [June 1, 2006, 6:44pm UTC](https://www.ruby-forum.com/t/more-flexible-file-column/62221/4 "2006-06-01T18:44:33Z")

</div>

> This is all a but un-rails-like though. I’d expect the plugin to  
> automatically realise that the resized image is missing and create it on  
> the fly. It has all the tools and data to do so, and the perfomance hit  
> will only be felt once, by the first user who encounters the image. I’d  
> take that to be an acceptable compromise.

I’m building something with file\_column right now and I think this is a  
great idea. I have to admit at first I thought you were just asking for  
more features. I listened to Sebastian speak at Canada on Rails and  
everyone was asking him ‘can you make it do this? How about this? What  
about this?’

The Rails rationale was to do what was right for most of the people most  
of the time, and I think this fits. Unfortunately I have not the  
technical know-how to help out with it yet, but let me know how it goes.

---

<div class="post-metadata">

**Author:** ![DJ\_Tequila](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@DJ\_Tequila](https://www.ruby-forum.com/u/DJ_Tequila)\
**Post date:** [June 1, 2006, 6:55pm UTC](https://www.ruby-forum.com/t/more-flexible-file-column/62221/5 "2006-06-01T18:55:01Z")

</div>

1. modify the model to support a new thumbnail size

2. 

Attachment.find(:all).each do |a|  
a.asset = File.open(a.asset) #opens each file\_column based asset  
a.save #rebuilds and saves - huzzah  
end

from our friends at caboose - reference :  
[http://blog.caboo.se/articles/2006/01/09/file\_column-magick-and-versions](http://blog.caboo.se/articles/2006/01/09/file_column-magick-and-versions)

-raja

Raja Bhatia, FiveLimes, Inc.  
http//fivelimes.com

---

<div class="post-metadata">

**Author:** ![DJ\_Tequila](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@DJ\_Tequila](https://www.ruby-forum.com/u/DJ_Tequila)\
**Post date:** [June 1, 2006, 7:28pm UTC](https://www.ruby-forum.com/t/more-flexible-file-column/62221/6 "2006-06-01T19:28:45Z")

</div>

On 6/1/06, DJ Tequila [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> all if you use Firefox.  
> This is why image transformations should be made in the view, not in  
> the model. the model should hold the canonical image, and the view  
> should create derivative images.\>

> I have, in fact, written such code quite successfully in PHP. However,  
> I’m new to Ruby and not completely comfortable with it yet. Has anyone  
> done it themselves? If not, has anyone looked into the File Column code  
> enough to give me a few pointers? Obviously if I get it working I’ll  
> release it back to the Rails community…

Check out my branch at [http://svn.kylemaxwell.com/file\_column/](http://svn.kylemaxwell.com/file_column/). It  
implements view-side image transformations. You’ll have to look  
through the source, particualarly magick\_file\_column.rb, since I  
haven’t kept up the docs.

I’m open to the idea of forking file\_column, as I am actively  
developing my branch. I used to work closely with Sebastian on  
file\_column development. This appears stalled, as a point release  
hasn’t happened in several months.

–  
Kyle M.  
Chief Technologist  
E Factor Media // FN Interactive  
removed\_email\_address@domain.invalid  
1-866-263-3261

---

<div class="post-metadata">

**Author:** ![DJ\_Tequila](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@DJ\_Tequila](https://www.ruby-forum.com/u/DJ_Tequila)\
**Post date:** [June 2, 2006, 7:13am UTC](https://www.ruby-forum.com/t/more-flexible-file-column/62221/7 "2006-06-02T07:13:43Z")

</div>

> It wasn’t quite 1500 images, but I ended up writing a script to  
> systematically go through each image in the database and resize it to  
> order… File column helpfully handles removing the old sizes for you.

Acts as attachment supports multiple thumbnails for a single image. I  
usually store the original image plus any smaller versions I may need.  
I’ve changed thumbnail sizes several times during the development of  
my current client project. I just loop through all uploaded images  
and re-process everything in script/console.

If you’re doing this kind of thing often, maybe you need a different  
solution?

> **[Agile Asset Management with Ruby DSLs](https://www.infoq.com/articles/Agile-Asset-Management/)**
>
> Ruby makes it easy to craft Domain-Specific-Languages with Ruby syntax. This article is a story about the benefits derived from implementing a Ruby DSL for a PLANET ARGON development project.
