Forum: Ruby on Rails File_column

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
scidept (Guest)
on 2005-12-01 23:35
(Received via mailing list)
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 %>
  <tr>

    <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?' %></td>

  </tr>

<% 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
francois.beausoleil (Guest)
on 2005-12-01 23:43
(Received via mailing list)
Hi !

2005/12/1, BJ Clark <removed_email_address@domain.invalid>:
> 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 !
scidept (Guest)
on 2005-12-02 00:28
(Received via mailing list)
Works beautifully!
Thanks,
BJ Clark
Kris L. (Guest)
on 2005-12-02 12:02
(Received via mailing list)
"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.
renaud morvan (Guest)
on 2007-09-26 01:05
(Received via mailing list)
On 6/29/07, Yann KLIS <removed_email_address@domain.invalid> 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
This topic is locked and can not be replied to.