我要填充的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
    }
 }

我用于创建供应商的 Controller 代码是
  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

在运行带有post的http://localhost:3000/vendors/create_vendor链接时,状态显示为200 ok,但是当我查找JSON响应时,对于已创建的供应商,它会引发意外的'
ruby-on-rails - 使用Postman和rails时发生意外的'<'错误-LMLPHP

最佳答案

我遇到了同样的问题,并且可以通过更改同步链接来对其进行排序

关于ruby-on-rails - 使用Postman和rails时发生意外的'<'错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39528606/

10-10 10:49