Forum: Ruby on Rails Trouble with rendering partials

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F9baac8d679b8728c0b8023e34c61666?d=identicon&s=25 Eleo (Guest)
on 2006-03-27 02:44
This only works when the partial name matches the object name; if I
change "threadtop" to "thread" then it works fine.  Is this normal? I
get the following error otherwise:

"undefined local variable or method `thread'"

index.rhtml
---
<% for @thread in @threads %>
  <%= render :partial => 'threadtop', :object => @thread %>
  <% for @reply in @replies %>
    <%= render :partial => "reply", :object => @reply %>
  <% end %>
<% end %>


_threadtop.rhtml:
---
<div class="threadtop">
<% if thread.image_name != "" %>
<% end %>

<p>
  <span class="subject"><%= thread.subject %></span>
  <span class="name"><%= thread.name %></span>
  <span class="date"><%= thread.date.strftime("%m/%d/%Y %H:%M")
%></span>
  <span class="num">No. <%= thread.num %></span>
  <span class="reply">
    [<%= link_to "Reply", :controller => ["imageboard", params[:board]],
:action => ["reply"], :id => thread.num %>]
  </span>
</p>

<% if thread.comment != "" %>
<blockquote><%= thread.comment %></blockquote>
<% end %>
</div>
Ac1da5d66d51a1c3b843221032247b30?d=identicon&s=25 Eric Goodwin (Guest)
on 2006-03-27 02:50
(Received via mailing list)
Hi,
This should work.

<% for thread in @threads %>
  <%= render :partial => 'threadtop', :locals=> {:thread => thread } %>
  <% for reply in @replies %>
    <%= render :partial => "reply", :locals=> {:reply=> reply } %>
  <% end %>
<% end %>

-Eric
ericgoodwin.com
F9baac8d679b8728c0b8023e34c61666?d=identicon&s=25 Eleo (Guest)
on 2006-03-27 02:56
Thanks, that worked perfectly.
This topic is locked and can not be replied to.