我要填充的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响应时,对于创建的供应商,它会抛出意外的'
我遇到了同样的问题,并且能够通过更改同步链接对其进行排序
请确保在User=require('../Models/user');
和主route/user.js
中都没有两次声明模型类的var server/app.js file
对象两次
您两次声明对象为模型类
邮递员应用程序中的此设置帮助我解决了此问题
全局代理配置:开启
代理类型:HTTPS
代理服务器:abc.xyz.abc.com:8080
使用系统代理:OFF
原因是您可能在尝试连接邮递员时通过登录其他浏览器或其他地方打开了会话。这就是您收到“意外的'>'”的原因。
[为避免这种情况,请使用登录api登录邮递员,然后尝试使用您的服务。它肯定会工作。