我有一个名为Product的模型,无论我做什么,我都无法使用to_params来工作。网址始终为website_name / shop / product.id。提前谢谢。
这是我的产品型号:
class Product < ActiveRecord::Base
self.table_name = 'STOCK'
self.primary_key = 'NUMBER'
def to_param
"#{NUMBER} #{DESC1}".parameterize
end
has_one :product_override, foreign_key: 'sku'
end
这是我的Shop Controller索引操作:
class ShopController < ApplicationController
before_action :set_product, only: [:show, :edit, :update, :destroy]
def index
#params[:category] ||= 'CAMERAS'
#q = params[:category]
@featured = Product.joins(:product_override).where("product_overrides.featured = ? and product_overrides.active = ?",1,1).where("DISCONT = ? and NONPRODUCT = ?" ,0,0).limit(18)
end
end
以下是我视图中的链接:
<%= link_to product.NUMBER, shop_path(product.id) %>