2012-09-15 146 views
0

不同的模板,我用渲染軌道

<%= render :partial => @list.items%> 

一個視圖以顯示該命令稱_item.html.erb。對?

<div class="well"> 
    <%= image_tag item.photo.url(:small) %><br> 
    <b>Title</b> <%= item.title %><br /> 
    <b>Description</b> <%= item.description %> 
</div> 

這工作正常。 現在我有一個叫_ilist.html.erb的其他模板,我需要這些數據。 我嘗試通過添加模板選項來進行渲染。但其他模板不會使用。第一個模板將隨時調用。

<%= render :partial => @list.items, :template => 'items/ilist' %> 

是否有任何選項可以調用其他_ilist-template?

感謝您的幫助

回答

1

我相信你需要:

<%= render :partial => 'items/ilist', :collection => @list.items, :as => :item %> 
+0

謝謝你完蛋了。但現在我得到兩個線路的誤差(爲一個測試我複製item.html.erb)爲# '

<%= image_tag item.photo.url%>
Wunsch:<%= item.title %>
Beschreibung:<%= item.description %>

Reservieren

'' 未定義局部變量或方法'項」 <#<類別:0x000000032c0e40>: 0x007fcb645f8390> – amarradi

+1

在你的渲染語句中也傳入「:as =>:item」 – cpuguy83

+0

非常感謝,它運行良好。現在我知道這個聲明的含義 – amarradi