我遇到了显示专柜类别的小问题。我想要在我的索引页面上显示类别名称和图像,类别名称充当到类别页面的链接,其中显示此类别的产品。我有我的看法如下代码:专柜类别路由
<% @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