第一次問一個問題並不確定我是否正確地做了這件事,但是在這裏。我收到此錯誤獲取「表單中的第一個參數不能包含零或爲空」錯誤
在形式上不能包含零或爲空 /nameofapp/app/views/products/_form.html.erb第一個參數,其中線#1提出:
這裏有我的鏈接:
視圖
<%= form_for(@product) do |f| %>
<% if @product.errors.any? %>
<div id="error_explanation">
控制研究呃
class ProductsController < ApplicationController
before_action :set_product, only: [:show, :edit, :update, :destroy]
# GET /products
# GET /products.json
def index
@products = Product.all
end
# GET /products/1
# GET /products/1.json
def show
end
# GET /products/new
def new
@product = Product.new
end
# GET /products/1/edit
def edit
end
# POST /products
# POST /products.json
def create
@product = Product.new(product_params)
respond_to do |format|
if @product.save
format.html { redirect_to @product, notice: 'Product was successfully created.' }
format.json { render :show, status: :created, location: @product }
else
format.html { render :new }
format.json { render json: @product.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /products/1
# PATCH/PUT /products/1.json
def update
respond_to do |format|
if @product.update(product_params)
format.html { redirect_to @product, notice: 'Product was successfully updated.' }
format.json { render :show, status: :ok, location: @product }
else
format.html { render :edit }
format.json { render json: @product.errors, status: :unprocessable_entity }
end
end
end
# DELETE /products/1
# DELETE /products/1.json
def destroy
@product.destroy
respond_to do |format|
format.html { redirect_to products_url, notice: 'Product was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_product
@product = Product.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def product_params
params.require(:product).permit(:name, :description, :image_url, :colour, :price)
end
末 #PATCH/PUT /產品/ 1 #PATCH/PUT /products/1.json 高清更新 的respond_to做|格式| if @ product.update(product_params) format.html {redirect_to @product,notice:'Product was successfully updated。' } format.json {render:show,status:ok,location:@product else format.html {render:edit} format.json {render json:@ product.errors,status::unprocessable_entity} 最終 結束 結束
# DELETE /products/1
# DELETE /products/1.json
def destroy
@product.destroy
respond_to do |format|
format.html { redirect_to products_url, notice: 'Product was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_product
@product = Product.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def product_params
params.require(:product).permit(:name, :description, :image_url, :colour, :price)
end
末
你做錯了。請在問題中包含相關的代碼和錯誤。 –
是更好嗎? – Frank
@Frank請包括完整的錯誤。通常它指向一行代碼或對象/方法來查看。 – onebree