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 %> <div id="chat_content_<%= contact.partner_id%>"> <%= render(:partial => contact.partner_id) %> </div> <div> <% form_tag ... do %> . . . <% end %> </div> <% end %> -- Posted via http://www.ruby-forum.com/.
On 22 Sep 2009, at 11:38, Ngassa Carine 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 > This is the view: > > <% for contact in @contacts %> > <div id="chat_content_<%= contact.partner_id%>"> > <%= 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> > <div> > <% form_tag ... do %> > . . . > <% end %> > </div> > <% end %> > -- > Posted via http://www.ruby-forum.com/. > > >
Ngassa Carine 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 nameSounds 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? -- Posted via http://www.ruby-forum.com/.
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. -- Posted via http://www.ruby-forum.com/.