# What am I doing wrong?

**URL:** <https://www.ruby-forum.com/t/what-am-i-doing-wrong/175894>\
**Category:** Rails\
**Created:** [September 22, 2009, 12:38pm UTC](https://www.ruby-forum.com/t/what-am-i-doing-wrong/175894 "2009-09-22T12:38:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pl\_helpme](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/fbc32d/32.png) [@pl\_helpme](https://www.ruby-forum.com/u/pl_helpme)\
**Post date:** [September 22, 2009, 12:38pm UTC](https://www.ruby-forum.com/t/what-am-i-doing-wrong/175894/1 "2009-09-22T12:38:29Z")

</div>

Hello,

I’m trying to display chat messages from different users, and the  
content is to be read from respective partials.  
When I render the partials, I get the following error: `@…’ is not  
allowed as an instance variable name  
This is the view:

\<% for contact in @contacts %\>

 \<%= render(:partial =\> contact.partner\_id) %\> 

 \<% form\_tag ... do %\> . . . \<% end %\> 
 \<% end %\>

---

<div class="post-metadata">

**Author:** ![pl\_helpme](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/fbc32d/32.png) [@pl\_helpme](https://www.ruby-forum.com/u/pl_helpme)\
**Post date:** [September 22, 2009, 2:30pm UTC](https://www.ruby-forum.com/t/what-am-i-doing-wrong/175894/2 "2009-09-22T14:30:30Z")

</div>

Ngassa C. wrote:

> Hello,
> 
> I’m trying to display chat messages from different users, and the  
> content is to be read from respective partials.  
> When I render the partials, I get the following error: `@…’ is not  
> allowed as an instance variable name

Sounds like you need to render the partial and pass in the variable as  
a local variable:  
\<%= render :partial ‘mypartial’, :locals =\> { :contacts =\> @contacts }  
%\>

And in the partial, you can now use the local variable ‘contacts’.  
Try that?

---

<div class="post-metadata">

**Author:** ![pl\_helpme](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/fbc32d/32.png) [@pl\_helpme](https://www.ruby-forum.com/u/pl_helpme)\
**Post date:** [September 23, 2009, 2:04am UTC](https://www.ruby-forum.com/t/what-am-i-doing-wrong/175894/3 "2009-09-23T02:04:13Z")

</div>

On 22 Sep 2009, at 11:38, Ngassa C. wrote:

> \<%= render(:partial =\> contact.partner\_id) %\>
> 
> Are you partial names just numeric values ? That won’t work because  
> instance/local variables get created for you named after the partial  
> and you can’t have an instance variable called @123
> 
> Fred

---

<div class="post-metadata">

**Author:** ![pl\_helpme](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/fbc32d/32.png) [@pl\_helpme](https://www.ruby-forum.com/u/pl_helpme)\
**Post date:** [September 22, 2009, 3:27pm UTC](https://www.ruby-forum.com/t/what-am-i-doing-wrong/175894/4 "2009-09-22T15:27:32Z")

</div>

Hi Aldric,

> Sounds like you need to render the partial and pass in the variable as  
> a local variable:

that’s what I also thought, but I resolved the problem by using  
a different formating for ‘mypatrial’, and not contact.partner\_id. The  
problem is that not all ‘partner\_ids’ also form a valid partial name,  
since there exist some signs(like -, $ …) which are not allowed in  
file names.

Thanks for the help.
