我希望我的rails控制器索引操作一次呈现多个输出,我的控制器:
class Api::V1::Ola::OlaBookingsController < ApplicationController
def index
lat = params[:lat].to_s
long = params[:long].to_s
drop_lat = params[:drop_lat].to_s
drop_lng = params[:drop_lng].to_s
ola_query = {
"pickup_lat" => lat,
"pickup_lng" => long,
"drop_lat" => drop_lat ,
"drop_lng" => drop_lng
}
ola_body = {
"pickup_lat" => lat,
"pickup_lng" => long,
"drop_lat" => drop_lat,
"drop_lng" => drop_lng,
"pickup_mode" => "NOW",
"category" => "auto"
}
ola_headers = {
"Authorization" => "Bearer ",
"X-APP-TOKEN" => ""
}
@ola_products = HTTParty.get(
"http://sandbox-t.olacabs.com/v1/products",
:query => ola_query,
:headers => ola_headers
).parsed_response
@ola_booking = HTTParty.post(
"http://sandbox-t.olacabs.com/v1/bookings/create ",
:body => ola_body,
:headers => ola_headers
).parsed_response
render :json => @ola_booking
render :json => @ola_products
end
end
我希望两个响应都能在控制器上出现,而不会生成视图。 但它给出了“多重渲染不可能”的错误,如何修复它?
答案 0 :(得分:1)
你不能有2个渲染,你可以做的是一个接一个地组合2个对象,如
render :json => @ola_booking.to_json + @ola_products.to_json
你应该尝试一下,让我知道它是如何运作的
答案 1 :(得分:0)
你可以试试这个。
public TextureRegion(Texture texture)