# Render collection undefined local variable

**URL:** <https://www.ruby-forum.com/t/render-collection-undefined-local-variable/64590>\
**Category:** Rails\
**Created:** [February 7, 2006, 10:34pm UTC](https://www.ruby-forum.com/t/render-collection-undefined-local-variable/64590 "2006-02-07T22:34:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jebus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@Jebus](https://www.ruby-forum.com/u/Jebus)\
**Post date:** [February 7, 2006, 10:34pm UTC](https://www.ruby-forum.com/t/render-collection-undefined-local-variable/64590/1 "2006-02-07T22:34:03Z")

</div>

Why am I getting undefined local variable ‘contact’ in my partial.  
This is code I used to render the partial, works in lots of other places

\<%= render (:partial =\> ‘list’, :collection =\> @contacts) %\>

in my parital I have  
\<%= contact.first\_name %\>

if I write this way it works fine  
\<% for contact in @contacts %\>  
\<%= render (:partial =\> ‘list’, :locals =\> {:contact =\> contact } ) %\>  
\<% end %\>

@contacts is being loaded with a paginate in my controller. any ideas ?

joe

---

<div class="post-metadata">

**Author:** ![Jebus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@Jebus](https://www.ruby-forum.com/u/Jebus)\
**Post date:** [February 7, 2006, 10:37pm UTC](https://www.ruby-forum.com/t/render-collection-undefined-local-variable/64590/2 "2006-02-07T22:37:12Z")

</div>

For your render method use

:partial =\> ‘contact’

Kent.

---

<div class="post-metadata">

**Author:** ![Jebus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@Jebus](https://www.ruby-forum.com/u/Jebus)\
**Post date:** [February 7, 2006, 10:37pm UTC](https://www.ruby-forum.com/t/render-collection-undefined-local-variable/64590/3 "2006-02-07T22:37:13Z")

</div>

Hi Jebus ~

The local variable will have the same name as the partial. So in this  
case, your local variable is named list. So list.first\_name will  
work.

If you want to use contact, rename your partial to \_contact.rhtml.

~ Ben

On 2/7/06, Jebus [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<%= render (:partial =\> ‘list’, :locals =\> {:contact =\> contact } ) %\>  
> \<% end %\>
> 
> @contacts is being loaded with a paginate in my controller. any ideas ?
> 
> joe
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Ben R.  
[http://www.benr75.com](http://www.benr75.com)
