Forum: Ruby on Rails partials and instance variables for 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.
Beate P. (Guest)
on 2006-01-19 22:22
(Received via mailing list)
Hi,

Sebastian K. of the file_column-Plugin wrote once:

"is the photo object inside a local variable or an instance variable
(e.g. photo or @photo)? url_for_file_column only works with instance
variables, like all other active record form helpers. Could this be
the problem?"

So I'm using file_column in a partial, e.g.

<%= render (:partial => "product", :collection => @products) %>

my partial (_product.rhtml) looks like this:

<div class="productteaser">
   <h4><%= link_to product.titel, :action => 'detail', :id => product.id
%></h4>
     <%= link_to (image_tag url_for_file_column("product", "image"),
{:width => '150', :height => '181', :style => ""}), { :action =>
'detail', :id => product.id }, {:title => "Detailansicht" } %>
  <p class="preis"><%= product.preis %> </p>
</div>

But in my partial I have the local variable "product", not the
instance variable @product, so file_column doesn't work. I now have a

<% @product  = product %>
in the top of my partial, but I think there must be a more railish way.
But how?

Thanks,
Beate
Kyle M. (Guest)
on 2006-01-20 01:48
(Received via mailing list)
On 1/19/06, Beate P. <removed_email_address@domain.invalid> wrote:
>
> </div>
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>

url_for_file_column now lets you cheat and pass the object itself
where most rails fields only accept the string name of the object.
i.e.

url_for_file_column "instance_var", "field"
url_for_file_column @instance_var, "field"
url_for_file_column local_var, "field"

are all valid.

--
Kyle M.
Chief Technologist
E Factor Media // FN Interactive
removed_email_address@domain.invalid
1-866-263-3261
This topic is locked and can not be replied to.