【发布时间】:2019-06-12 23:05:54
【问题描述】:
在 Rails 上调试我的第一个项目时出现以下错误:
NoMethodError(未定义的方法 `product_url' 用于# 你的意思是? products_url):
app/controllers/products_controller.rb:13:in `create'
class ProductsController < ApplicationController
def show
@product = Product.find(params[:id])
end
def new
end
def create
@product = Product.new(product_params)
@product.save
redirect_to @product
end
private
def product_params
params.require(:product).permit(:title, :price, :count)
end
end
---------config/routes.rb------
Rails.application.routes.draw 做 得到“欢迎/索引” 资源:产品 根“欢迎#index”
结束
---------rake 路由----------
Prefix Verb URI Pattern Controller#Action
welcome_index GET /welcome/index(.:format) welcome#index
new_products GET /products/new(.:format) products#new
edit_products GET /products/edit(.:format) products#edit
products GET /products(.:format) products#show
PATCH /products(.:format) products#update
PUT /products(.:format) products#update
DELETE /products(.:format) products#destroy
POST /products(.:format)
【问题讨论】:
-
如果您编辑您的问题(使用标签下方的
edit链接)以包括(1)config/routes.rb的相关部分和(2)@ 的控制台输出,这可能会有所帮助987654325@.
标签: ruby-on-rails