因此,我们将 ruby gem 与 sinatra CRUD 应用程序一起使用,为第三方“送礼”提供交货报价和后续交货。
这是发送 post 请求的 HTML 表单:
<form method="POST" action="/v1/customers/10/delivery_quotes">
<input type="hidden" name="request[requestor_id]" value="10"/>
<input type="text" name="request[pickup_name]" placeholder="Restaurant Name"/>
<input type="text" name="request[pickup_address]" placeholder="Restaurant Address"/>
<input type="text" name="request[pickup_phone_number]" placeholder="Restaurant Phone #"/>
<textarea type="text" name="request[manifest]" placeholder="Your order"></textarea>
<input type="text" name="request[dropoff_phone_number]" placeholder="Your Phone #"/>
<input type="text" name="request[dropoff_address]" placeholder="Your Address"/>
<input type="text" name="request[dropoff_name]" placeholder="Your Name"/>
<input type="text" name="request[dropoff_notes]" placeholder="Notes"/>
<input type="submit" value="Request" />
</form>
我们控制器中的 POST 路由:
post '/v1/customers/:customer_id/delivery_quotes' do
@client = Postmates.new
@request = Request.create!(params[:request])
from = params[:request][:pickup_address]
to = params[:request][:dropoff_address]
post_quote = @client.quote(pickup_address: from, dropoff_address: to)
@quote = Quote.new(request_id: @request.id, detail_hash: post_quote)
if @quote.save
redirect "/"
else
erb :"/requests/new"
end
end
在堆栈跟踪中,法拉第中间件中抛出了错误,但我已经检查了所有版本控制并且它都排成一行。有没有其他人遇到过这个错误?