Probems with partials and instance variable

view:

<%= drop_receiving_element(‘image_basket’,
:accept => “image”,
:complete => “$(‘spinner’).hide()”,
:before => “$(‘spinner’).show()”,
:update => “image_basket” , :url => {:action => “basket”}) %>

controller:

def basket
image_id = params[:id].split(“_”)[1]
unless session[:basket].include?(image_id)
session[:basket][image_id] = image_id
end

 @images = Image.find(:all, :conditions => ["id = #{image_id}]")
 render :partial => "basket" , :layout => false

end

_basket.rhtml

This work ok:

<%= @images.inspect %>

I get something like:

[#“image/jpeg”, “galery_id”=>“2”, “size”=>“119121”,
“thumbnail”=>nil, “id”=>“1”, “description”=>“”, “deleted”=>“0”,
“height”=>“427”, “filename”=>“IMG_0427.jpg”, “parent_id”=>nil,
“width”=>“640”}>, #“image/jpeg”, “galery_id”=>nil, “size”=>“119121”,
“thumbnail”=>“thumb”, “id”=>“2”, “description”=>nil, “deleted”=>nil,
“height”=>“100”, “filename”=>“IMG_0427_thumb.jpg”, “parent_id”=>“1”,

This does not work:

<% @images.each do |bi| %>
<%= bi.filename %>
<% end %>

I get something link:

You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
Whats wrong here??


Jochen K.
gissmoh.de, figgfrosch.de, ror-ror.de

 @images = Image.find(:all, :conditions => ["id = #{image_id}]")

Is this a typo or have you actually done this?

Check the quotes, they are in the wrong place:

@images = Image.find(:all, :conditions => [“id = #{image_id}”])

Luke P. schrieb:

 @images = Image.find(:all, :conditions => ["id = #{image_id}]")

Is this a typo or have you actually done this?

Check the quotes, they are in the wrong place:

@images = Image.find(:all, :conditions => [“id = #{image_id}”])

it’s a typo.


Jochen K.
gissmoh.de, figgfrosch.de, ror-ror.de