我的routes.rb文件中包含以下内容:
match "/service/:product" => "products#show_name"
match "/products/custom/" => "products#custom"
match "/products/customform" => "products#customform"
match "/categories" => "products#categories"
match "/search" => "products#search"
match "/about" => "products#about"
get 'category/:tag', to: 'products#category', as: :tag
resources :products do
resources :reviews
end
我正在尝试访问网址“/ service / birchbox”。当我这样做时,我得到一个错误说
No route matches {:action=>"edit", :controller=>"products"}
有关如何解决此问题的任何建议?我试图让这个网址转到列出的第一个路由(到控制器产品#show_name但由于某种原因将要编辑)。
以下是我在控制台中看到的更多信息。好像它会显示show_name,但我一直收到错误。
Processing by ProductsController#show_name as HTML
Parameters: {"product"=>"birchbox"}
Product Load (0.2ms) SELECT "products".* FROM "products" WHERE "products"."slug" = 'birchbox' LIMIT 1
(0.1ms) SELECT COUNT(*) FROM "reviews" WHERE "reviews"."product_id" = 14
ActsAsTaggableOn::Tag Load (0.1ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = 14 AND "taggings"."taggable_type" = 'Product' AND (taggings.context = 'tags' AND taggings.tagger_id IS NULL)
Rendered products/show_name.html.erb within layouts/application (97.3ms)
Completed 500 Internal Server Error in 164ms
ActionController::RoutingError (No route matches {:action=>"edit", :controller=>"products"}):
app/views/products/show_name.html.erb:42:in `_app_views_products_show_name_html_erb___2110533700820522490_70197663436420'
答案 0 :(得分:2)
似乎在第42行views/products/show_name.html.erb
你有类似的东西:
<%= edit_product_path %>
这条路线不存在。 edit
路由需要产品ID。试试这个:
<%= edit_product_path(@product) %>