Beate Paland
2006-Jan-19 19:43 UTC
[Rails] partials and instance variables for file_column
Hi,
Sebastian Kanthak 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 Maxwell
2006-Jan-19 23:11 UTC
[Rails] partials and instance variables for file_column
On 1/19/06, Beate Paland <bpaland@gmail.com> wrote:> Hi, > > Sebastian Kanthak 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 > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > 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 Maxwell Chief Technologist E Factor Media // FN Interactive kyle@efactormedia.com 1-866-263-3261