Url_for_file_column problems

Hello,

Has anyone got file_column working fully? it’s doing most of it’s job
properly, except for the url_for_file_column helper method. Whatever I
do, it’s always returning a nil. I tried reading the source, but not
entirely sure what it’s doing. Can somebody throw some light on this?

TIA,
Vamsee.

Sorry, don’t bother… I made a stupid mistake.

Vamsee K. wrote:


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


If you’re not living on the edge, you’re taking up too much room - Jayne
Howard

On 11/19/05, Vamsee K. [email protected] wrote:

Has anyone got file_column working fully? it’s doing most of it’s job
properly, except for the url_for_file_column helper method. Whatever I
do, it’s always returning a nil. I tried reading the source, but not
entirely sure what it’s doing. Can somebody throw some light on this?

it comes with proper rdocs that should more or less explain what it is
doing. If anybody has suggestions how to make this even more clearer
I’m more than happy to receive them.

Regarding your question: If your model is stored in an instance (!)
variable “@foo” and your file_column is called “image”, then you can
use it like this:

<%= url_for_file_column “foo”, “image” %>

Hope this helps
Sebastian

Sebastian K. wrote:

Regarding your question: If your model is stored in an instance (!)
variable “@foo” and your file_column is called “image”, then you can
use it like this:

<%= url_for_file_column “foo”, “image” %>

Thanks Sebastian, I solved this with some help on irc. However, maybe
I’m missing something basic, but I didn’t understand this part: I want
to list all the images as thumbnails in the list.rhtml.

This works:

<% for @contact in @contacts %>

<%=h @contact.name %> <%=h @contact.address %> <%= image_tag url_for_file_column "contact", "picture", "thumb" %> <% end %>

But this throws a nil error. Why?

<% for contact in @contacts %>

<%=h contact.name %> <%=h contact.address %> <%= image_tag url_for_file_column "contact", "picture", "thumb" %> <% end %>

TIA,
Vamsee.

Sebastian K. wrote:

simply followed this convention, but lots of people seem to have
trouble with it. Perhaps, I’ll come up with something else…

I did this in my copy of file_column_helper.rb:

def url_for_file_column(object_name, method, suffix=nil)
rel_path_method = “#{method}_relative_path”
opts_method = “#{method}_options”
if object_name.respond_to?(rel_path_method) &&
object_name.respond_to?(opts_method)
object = object_name
else
object = instance_variable_get("@#{object_name.to_s}")
end
relative_path = object.send(rel_path_method, suffix)
return nil unless relative_path
url = “”
url << @request.relative_url_root.to_s << “/”
url << object.send(opts_method)[:base_url] << “/”
url << relative_path
end

Basically it’ll accept either a named instance variable, or something
that looks like an AR instance with a named file_column. I think this
is closer to the convention. It certainly makes showing thumbnail lists
easier.

On 11/19/05, Vamsee K. [email protected] wrote:

<% for @contact in @contacts %>

<%= image_tag url_for_file_column “contact”, “picture”, “thumb” %>

But this throws a nil error. Why?

<% for contact in @contacts %>

<%= image_tag url_for_file_column “contact”, “picture”, “thumb” %>

because url_for_file_column expects the model in an instance
variable, as stated in the docs as well. This is a rails convention
that you’ll find in other helpers as well, for example text_field. I
simply followed this convention, but lots of people seem to have
trouble with it. Perhaps, I’ll come up with something else…

Sebastian

skanthak wrote:

On 11/19/05, Vamsee K. [email protected] wrote:

<% for @contact in @contacts %>

<%= image_tag url_for_file_column “contact”, “picture”, “thumb” %>

But this throws a nil error. Why?

<% for contact in @contacts %>

<%= image_tag url_for_file_column “contact”, “picture”, “thumb” %>

because url_for_file_column expects the model in an instance
variable, as stated in the docs as well. This is a rails convention
that you’ll find in other helpers as well, for example text_field. I
simply followed this convention, but lots of people seem to have
trouble with it. Perhaps, I’ll come up with something else…

Sebastian

I think the problem for many people is that you’re treating
url_for_file_column like a form helper. On an intuitive level, that
method doesn’t feel like a form helper at all (unlike
file_column_field). Since it returns img tag parameters and not a form
field at all, it would probably be less awkward and more intuitive if
you could simply say

<%= image_tag url_for_file_column(@contact.picture) %>

Okay, back to trying to figure out what on earth I’m doing wrong in my
own code.

-sk

could it also be that one of your contacts does not have an image to
work with? I ran into that in one of my apps and i had it display some
text if the image didn’t exist for a record…I would post the code but
i’m not at the pc my app was on…i believe it was quivanlent to

rescue ‘no image yet’ (which might have broken the iteration which then
led me to try…)

or

<% if @contact.picture == nil %> (maybe unless @contact.picture would
work as well?)

you don't have an image

<% end %>

or something similar…

this was from RoR noob memory so I wouldn’t trust it too much but that’s
what i remember from my implementation.

curtis
http://noobonrails.blogspot.com/

Steve K. wrote:

skanthak wrote:

On 11/19/05, Vamsee K. [email protected] wrote:

<% for @contact in @contacts %>

<%= image_tag url_for_file_column “contact”, “picture”, “thumb” %>

But this throws a nil error. Why?

<% for contact in @contacts %>

<%= image_tag url_for_file_column “contact”, “picture”, “thumb” %>

because url_for_file_column expects the model in an instance
variable, as stated in the docs as well. This is a rails convention
that you’ll find in other helpers as well, for example text_field. I
simply followed this convention, but lots of people seem to have
trouble with it. Perhaps, I’ll come up with something else…

Sebastian

I think the problem for many people is that you’re treating
url_for_file_column like a form helper. On an intuitive level, that
method doesn’t feel like a form helper at all (unlike
file_column_field). Since it returns img tag parameters and not a form
field at all, it would probably be less awkward and more intuitive if
you could simply say

<%= image_tag url_for_file_column(@contact.picture) %>

Okay, back to trying to figure out what on earth I’m doing wrong in my
own code.

-sk