在 products_controller.rb
# GET /search/'brand'
def brand
@product = Product.find_all_by_brand(params[:brand])
respond_to do |format|
format.html # brand.html.erb
end
end
在路线.rb
match '/search/:brand' => 'products#brand'
如果我尝试访问localhost:3000/search/Apple
,我会收到以下错误Couldn't find Product with id=Apple
有什么我想念的吗?还有其他我应该处理的文件吗?
更新
现在我得到了undefined method 'size' for nil:NilClass
,我什至不确定我改变了什么。
rails 执行的查询是select "products".* FROM "products" WHERE "products"."brand" = 'Apple' ORDER BY last_seen DESC
并且它们似乎返回了正确的产品。
应用程序跟踪
app/views/products/_product.html.erb:1:in
_app_views_products__product_html_erb___2255278_29707176' app/views/products/brand.html.erb:1:in
_app_views_products_brand_html_erb___464952485_38589588' app/controllers/products_controller.rb:52:in `brand'