在products_controller.rb導軌 - find_by_ *航線
# GET /search/'brand'
def brand
@product = Product.find_all_by_brand(params[:brand])
respond_to do |format|
format.html # brand.html.erb
end
end
在routes.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
,它們似乎返回正確的產品。
應用程序跟蹤
應用/視圖/產品/ _product.html.erb:1:
_app_views_products__product_html_erb___2255278_29707176' app/views/products/brand.html.erb:1:in
_app_views_products_brand_html_erb___464952485_38589588' 應用程序/控制器/ products_controller.rb:52:在`品牌」
@ house9,對不起,但我不明白你在說什麼。 – rlhh 2013-03-06 01:07:51
顯示視圖代碼'app/views/products/_product.html.erb'和調用代碼'app/views/products/brand.html.erb' - 您有一個無對象,也許您希望有一個產品目的? – house9 2013-03-06 16:14:08