# Conditional image resizing (file\_column)

**URL:** <https://www.ruby-forum.com/t/conditional-image-resizing-file-column/140687>\
**Category:** Rails\
**Created:** [June 17, 2008, 3:15pm UTC](https://www.ruby-forum.com/t/conditional-image-resizing-file-column/140687 "2008-06-17T15:15:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alfredogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dbc845/32.png) [@alfredogz](https://www.ruby-forum.com/u/alfredogz)\
**Post date:** [June 17, 2008, 3:15pm UTC](https://www.ruby-forum.com/t/conditional-image-resizing-file-column/140687/1 "2008-06-17T15:15:55Z")

</div>

Hi  
IÂ´m using file\_column plugin.  
I have a model (banner) with a field image.  
I need to resize this field in diferent sizes depending on the value of  
other field of the same model (level).

Normally I donÂ´t have this requeriment and I define image file\_columns  
this way:  
file\_column :image, :magick =\> { :versions =\> { “thumb” =\>  
“130x150”,“med” =\> “380x305”,“gr” =\> “600x400”} }

Is it posible to access model instance variables in the file\_columns  
definition?  
If not, Is it possible to redefine file\_column-magick versions in a  
callback?.

Perhaps IÂ´m missing something, WhatÂ´s the best way to achieve this?

Thanks.

–Alfredo–

---

<div class="post-metadata">

**Author:** ![alfredogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dbc845/32.png) [@alfredogz](https://www.ruby-forum.com/u/alfredogz)\
**Post date:** [June 17, 2008, 4:58pm UTC](https://www.ruby-forum.com/t/conditional-image-resizing-file-column/140687/2 "2008-06-17T16:58:37Z")

</div>

> Normally I don´t have this requeriment and I define image file\_columns  
> this way:  
> file\_column :image, :magick =\> { :versions =\> { “thumb” =\>  
> “130x150”,“med” =\> “380x305”,“gr” =\> “600x400”} }
> 
> Is it posible to access model instance variables in the file\_columns  
> definition?

sure, you can always replace a string by some erb output  
file\_column :image, :magick =\> { :versions =\> { “thumb” =\>  
“130x150”,“med” =\> “\<%= @image.level == 1 ? “380x305” : “480x405”  
%\>”,“gr” =\> “600x400”} }

would put 380x305 if @image.level is 1 otherwise use “480x405”  
There are a lot of ways to do this, depending on your needs.  
In the end it’s all text and can be conditionaly replaced with erb
