File_column

I’m trying to use the file_column plugin, and the upload portion of it
works
beautifully.
I’m trying to display the images now and I’m having a couple problems.
First is, when I try to use url_for_file_column, I get the following
error:
You have a nil object when you didn’t expect it!
The error occured while evaluating nil.image_relative_path

The Code I’m using is this:
<% for photo in @photos %>

<td><%= image_tag url_for_file_column("photo", "image") %></td>

<td><%=h item.name %></td>

<td><%=h item.description %></td>

<td><%= link_to 'Show', :action => 'show', :id => item %></td>

<td><%= link_to 'Edit', :action => 'edit', :id => item %></td>

<td><%= link_to 'Destroy', { :action => 'destroy', :id => item },

:confirm => ‘Are you sure?’ %>

<% end %>

Second, I don’t know how to specify which version of the photo I
uploaded to
use.
I have a “thumb” and a “medium” and then the native size uploaded. How
do I
differentiate between the two?

Any help is appreciated,
Thanks,
BJ Clark

Hi !

2005/12/1, BJ Clark [email protected]:

I’m trying to display the images now and I’m having a couple problems.
First is, when I try to use url_for_file_column, I get the following error:
You have a nil object when you didn’t expect it!
The error occured while evaluating nil.image_relative_path

This is because you need to have an instance variable and not a local
one:
<% for @photo in @photos %>

<% end %>

Second, I don’t know how to specify which version of the photo I uploaded to
use.
I have a “thumb” and a “medium” and then the native size uploaded. How do I
differentiate between the two?

url_for_file_column has a third parameter - version. If you leave it
off, you’ll get the original size, else you’ll get that named version.

Hope that helps !

Works beautifully!
Thanks,
BJ Clark

On 6/29/07, Yann KLIS [email protected] wrote:

Juste pour info, attachment_fu est le successeur de acts_as_attachment.
Quant à file_column, le plugin est un peu mort (pas de mise à jour depuis
2005), la commande d’install sur la page web ne fonctionne pas (la dernière
fois que j’avais essayé en tout cas, ce qui remonte à quelques mois
maintenant), etc.

Je suis d’accord avec Yann, de plus attachment_fu est beaucoup plus
modulaire, et propose des hooks partout ou on en a besoin (before
thumbnail,
before_resize …), supporte les fichiers en DB, ou sur S3 et pas
seulement
les fichiers plats, offre la possibilité de resizer les images avec
imageMagick ou image Science, … C’est un des rares plugin que je n’ai
pas
eu une folle envie de patcher pour le faire rentrer dans mes besoins.
Les
tests sont très bien fait et Rick a rajouté d’excellent helper pour
faciliter le tout.

Son seul défaut à mon avis, il est totalement concu pour stocker les
fichiers à uploader, c’est à dire que les fonctions acceptent comme
argument
des UploadedFile facon CGI. Résultat pour utiliser le plugin afin de
stocker
ou par exemple peupler sa base de donnée il faut faire du duck typing
pour
fournir un Object qui ressemble à ce qu’il attend. Ce qui est un peu
chiant
quand on stocke sur S3 ou en DB mais ne pose pas de problème quand ce
sont
des fichiers plats car rails a tout ce qu’il faut.

Renaud

“You have a nil object when you didn’t expect it!
The error occured while evaluating nil.image_relative_path”

You also get this or a similar error if the image field has not had a
path/filename set.
So you can either set a default value in the database, say
“/images/default.jpg” or do
image_tag url_for_file_column(“photo”, “image”) if @photo.image

Kris.