我遇到问题追踪为什么我的更新方法没有得到所需的参数。我有一个类似的测试显示和有效载荷工作。在这种情况下,有问题的路线是发票/ invoice_id/trip/id。如果您可以帮助我发现错误,并就如何在将来很好地解决这类问题提出任何建议。更新方法的参数数量错误(1代表2)
这是更新方法。
def update
if @trip.update(@trip.trip_id, trip_params)
head :no_content
else
render json: [@invoice, @trip].errors, status: :unprocessable_entity
end
end
使用以下私有方法。
private
def set_trip
@trip = Trip.where(:invoice_id => params[:invoice_id], :trip_id => params[:id])
end
def trip_params
params.require(:trip).permit(:trip_id, :depart_airport, :arrive_airport, :passenger_first_name, :passenger_last_name, :passenger_count, :departure_date, :merchant_id)
end
def load_invoice
@invoice = Invoice.find(params[:invoice_id])
end
end
我的失败测试看起来像这样。
test "should update trip" do
put :update, invoice_id: @invoice.invoice_id, id: @trip,
trip: {arrive_airport: @trip.arrive_airport,
depart_airport: @trip.depart_airport,
departure_date: @trip.departure_date,
passenger_count: @trip.passenger_count,
passenger_first_name: @trip.passenger_first_name,
passenger_last_name: @trip.passenger_last_name}
assert_response 204
end
只是为了检查,2是1还是1的错误2?你正在做从数据库加载的记录的任何模拟/存根? –