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'