Forum: Ruby on Rails url_for_file_column in parent model's view

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Alien8 Recordings (Guest)
on 2006-01-25 06:35
(Received via mailing list)
Hi All,

I am using the file_column plugin to upload images. The model that I
am using is simply called images (id, name, caption - name being the
"file" column) and it belongs_to a parent model called books which
has_many images. I was able to figure out how to enter the images
into the correct model when updating of form of the parent model
(books). Now I need to figure out how to view the images in simple
display view of the parent model (books).

I am not sure about the syntax of the url_for_file_column helper.
Here is what I have so far:

<% for image in @book.images %>
  <label for="image_name">Image:</label>
<div class="reviewfield"><%  url_for_file_column image,,
"thumb" %> </div><br />

<label for="image_caption">Caption</label>
<div class="reviewfield"><%= image.caption %></div><br />

<% end %>

Which produces the following error:
You have a nil object when you didn't expect it!
The error occured while evaluating nil.image.name_relative_path

I also have a more general question about this function. How could
url_for_file_column figure out which model object (record) to display
if we are only to pass it the names of the model and relevant
attribute? Shouldn't we have to pass it an ID as well?

Alien8 Recordings (Guest)
on 2006-01-25 08:22
(Received via mailing list)
Hi All,

I actually was able to get this to work after doing some more
searching. In case anyone else stumbles up this, there were two
problems with my code. First I used <% instead of <%= so nothing was
being output. Second, when iterating over an array you have to use <%
= image_tag url_for_file_column "image", "name", "thumb" %> instead
of just <%= url_for_file_column "image", "name", "thumb" %>

Sorry for the noise.


On 24-Jan-06, at 11:34 PM, Alien8 Recordings wrote:

> I am not sure about the syntax of the url_for_file_column helper.
> <% end %>
> Thanks,
> Sean
> _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid

This topic is locked and can not be replied to.