Rails的通過讓我們直接通過收集變量render
方法像下面爲我們節省了each
環:如何在Rails中使用render @collection時使用不同名稱的文件?
<%= render @products %>
默認情況下,它會尋找一個名爲_product.html.erb文件,並使其對於@products
集合中的每個單個項目。不知何故,該文件已被命名爲_custom_product.html.erb,現在如何告訴render
方法來呈現名稱不同於標準的文件_product.html.erb?
請問這個'< %=渲染部分:「custom_product」,集合:@products%>'工作? – Pavan
@Pavan不,它不起作用。它說_custom_product.html.erb中的未定義變量'產品' –