# Probems with partials and instance variable

**URL:** <https://www.ruby-forum.com/t/probems-with-partials-and-instance-variable/109538>\
**Category:** Rails\
**Created:** [July 16, 2007, 3:50pm UTC](https://www.ruby-forum.com/t/probems-with-partials-and-instance-variable/109538 "2007-07-16T15:50:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jochen\_kaechelin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@jochen\_kaechelin](https://www.ruby-forum.com/u/jochen_kaechelin)\
**Post date:** [July 16, 2007, 3:50pm UTC](https://www.ruby-forum.com/t/probems-with-partials-and-instance-variable/109538/1 "2007-07-16T15:50:23Z")

</div>

# 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](http://gissmoh.de), [figgfrosch.de](http://figgfrosch.de), [ror-ror.de](http://ror-ror.de)

---

<div class="post-metadata">

**Author:** ![jochen\_kaechelin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@jochen\_kaechelin](https://www.ruby-forum.com/u/jochen_kaechelin)\
**Post date:** [July 16, 2007, 5:57pm UTC](https://www.ruby-forum.com/t/probems-with-partials-and-instance-variable/109538/2 "2007-07-16T17:57:47Z")

</div>

> ```
> @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}”])

---

<div class="post-metadata">

**Author:** ![jochen\_kaechelin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@jochen\_kaechelin](https://www.ruby-forum.com/u/jochen_kaechelin)\
**Post date:** [July 16, 2007, 6:06pm UTC](https://www.ruby-forum.com/t/probems-with-partials-and-instance-variable/109538/3 "2007-07-16T18:06:39Z")

</div>

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](http://gissmoh.de), [figgfrosch.de](http://figgfrosch.de), [ror-ror.de](http://ror-ror.de)
