elasticsearch,Ruby On Rails,Json,Ajax,elasticsearch" /> elasticsearch,Ruby On Rails,Json,Ajax,elasticsearch" />

Ruby on rails Rails-向JSON添加变量?

Ruby on rails Rails-向JSON添加变量?,ruby-on-rails,json,ajax,elasticsearch,Ruby On Rails,Json,Ajax,elasticsearch,我使用这种方法从ajax调用中传回装备: def givemeoutfits if current_user @outfits = Outfit.search(params[:search],1000000,1,1000000,1,1000000,1,1000000,1).page(1).per(7).results @results = Outfit.search(params[:search],1000000,1,1000000,1,1000000,1,1000000,

我使用这种方法从ajax调用中传回装备:

def givemeoutfits
  if current_user
    @outfits =  Outfit.search(params[:search],1000000,1,1000000,1,1000000,1,1000000,1).page(1).per(7).results
    @results = Outfit.search(params[:search],1000000,1,1000000,1,1000000,1,1000000,1).page(1).per(7).results.total_count
    if request.xhr?
      render status: 200, json: @outfits
  end
end 
end

我想将整数“results”添加到@oughts生成的json中,并返回到ajax调用。我该怎么做呢?

您只是想在返回的JSON对象中包含
@results
,如下所示

render status: 200, json: {
  outfits: @outfits,
  results: @results
}

然后,在javascript中,您可以与这两个键进行交互。

您是否只想在返回的JSON对象中包含
@results
,如下所示

render status: 200, json: {
  outfits: @outfits,
  results: @results
}

然后,在javascript中,您可以使用两个键进行交互。

当然可以,祝您好运!如果这个答案澄清了一切,你能把它标记为接受吗?谢谢当然-我该怎么做?谢谢!如果我记得的话,你应该会在我的答案左边看到一个复选标记,让你把它标记为“接受”。另外,欢迎使用堆栈溢出!当然,祝你好运!如果这个答案澄清了一切,你能把它标记为接受吗?谢谢当然-我该怎么做?谢谢!如果我记得的话,你应该会在我的答案左边看到一个复选标记,让你把它标记为“接受”。另外,欢迎使用堆栈溢出!