我遇到了顯示專櫃類別的小問題。我想要在我的索引頁面上顯示類別名稱和圖像,類別名稱充當到類別頁面的鏈接,其中顯示此類別的產品。我有我的看法如下代碼:專櫃類別路由
<% @products.each do |category, products| %>
<%= link_to category.name, product_category_path %>
<% end %>
但它返回我一個錯誤undefined local variable or method 'product_category_path' for #<#<Class:0xb22076fc>:0xb2205870>
我應該爲類控制器,以及用於產品?因爲現在我只有products_controller.rb
用下面的代碼:
class ProductsController < ApplicationController
def index
@products = Shoppe::Product.root.ordered.includes(:product_categories, :variants)
@products = @products.group_by(&:product_category)
end
def show
@product = Shoppe::Product.root.find_by_permalink(params[:permalink])
end
end
您能否看到'rake routes'並查看您是否使用了正確的路由幫助器路徑 – illusionist
u應該沒問題,只需傳遞一個類別id'<% = link_to category.name,product_category_path(category.id)%>' – 7urkm3n