Trouble with rendering partials


#1

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:

<% if thread.image_name != "" %> <% end %>

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

<% if thread.comment != “” %>

<%= thread.comment %>
<% end %>

#2

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


#3

Thanks, that worked perfectly.