我想在我的application.html.erb中渲染部分內容。部分源自產品文件夾「產品/類別」。當我嘗試在application.html.erb中插入一個部分時,如下所示,我得到#<#:0x007fcfa35c9c78>的未定義局部變量或方法`類別'。任何幫助是極大的讚賞。傳入部分對象
application.html.erb
<%= render 'products/categories', locals: { categories: categories }%>
產品/ _categories.html.erb
<% @categories.each do |category| %>
<li><%= category %></li>
<% end %>
products_controller.rb
def categories
@categories = ProductCategory.all
end
我最後做的是剛剛創建的helper方法,並在_categories.html.erb引用它。我無法得到任何其他工作。 – RickD