0
要填充我的JSON響應如下:意外「<」錯誤後,同時使用郵差和軌道
{
"vendor":
{
"name": "Mozelle Luettgen MD",
"email": "[email protected]",
"phone_no": "9999997660",
"addressline1": "Kulas Stravenue",
"addressline2": "64636 Lynch Springs",
"landmark": "Apt. 142",
"city": "South Hannaview",
"state": "North Dakota",
"country": "Palau",
"pincode": "53912-6122",
"latitude": 50.8247548421224,
"longitude": -81.8429583068792,
"status": true
}
}
我給創建廠商控制器代碼是
def create
@vendor = Vendor.new(vendor_params)
respond_to do |format|
if @vendor.save
format.html { redirect_to @vendor, notice: 'Vendor was
successfully created.' }
format.json { render :show, status: :created, location: @vendor,
:msg => { :status => "ok" , :result => @vendor.json, :message =>
"Succesfully Created" }
}
else
format.html { render :new }
format.json { render json: @vendor.errors, status:
:unprocessable_entity,
:msg =>
{ :status => "Error", :message => "Unprocessable Entity" }
}
end
end
end
def vendor_params
params.require(:vendor).permit(:name, :email, :phone_no,
:addressline1, :addressline2, :landmark,
:city, :state, :country, :pincode, :latitude, :longitude, :status,
{products_attributes: [:id, :product_name, :price]},
{vendor_products_attributes: [:id, :vendor_product_id, :vendor_id,
:product_id, :copies, :_destroy]})
end
當運行此鏈接http://localhost:3000/vendors/create_vendor與帖子,狀態顯示200確定,但是當我尋找JSON響應,對於創建的供應商,它會拋出意想不到的'<'錯誤。我做錯了什麼。可以請某人詳細說明
你是否使用調試器檢查過,你在控制器上得到了什麼參數? – power
我已更新顯示允許的參數的問題。 –
我認爲@power是要求在Postman中運行事務時,在控制器中實際存在哪些參數的調試器視圖。 –