Forum: Ruby on Rails file_column - url_for_file_column issue.

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.
036be8d5d83a98e546b98d64e3fd6c20?d=identicon&s=25 Sam Donaldson (Guest)
on 2006-05-08 03:10
(Received via mailing list)
Hi,

url_for_file_column @variable, 'name', takes an instance variable.  My
question is, what if I don't want to have to retrieve the instance
variable
every single time but I have the image id, along with its name with me.
Could I contruct that object in a view and pass it to
url_for_file_column:

<% @picture = Picture.new %>
     @picture.id = ...
     @picture.name = ...
%>

and then pass @picture in?  I tried this but when I tried the name
assignment, I got the following:

Do not know how to handle a string with value 'somename.jpg' that was
passed
to a file_column.

Thanks.
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-05-08 10:29
(Received via mailing list)
Sam Donaldson wrote:
>      @picture.name <http://picture.name> = ...
> %>
>
> and then pass @picture in?  I tried this but when I tried the name
> assignment, I got the following:
>
> Do not know how to handle a string with value 'somename.jpg' that was
> passed to a file_column.
I'm pretty sure (away from devbox at the moment) that a file_column
field actually wants to be passed a FileIO (or StringIO, I think) object
so that it can handle the actual data.

In this case, you may well be better off either creating a mock class
that supports the methods that url_for_file_column requires (which I
*think* will be limited to name, id and class), or writing your own
helper to use instead of url_for_file_column.
This topic is locked and can not be replied to.