0
I’m trying to create a select where returns data in json and then created a method that would be a "database" that is another select bringing a result, as I would to juxtapose all this and bring a json only?
class ConsolidatedOrdersController < ApplicationController
def index
json_date = []
dt_inicio = fc_inicio(931101)
json_date = Order.left_outer_joins(:load, :user, :pallet_kind, :order_priority, step: [:status, :role])
.select('orders.*','loads.*', 'statuses.name as Status', 'pallet_kinds.name as Tipo_de_Pallet', 'order_priorities.name as Prioridade')
.where('orders.step' => 500)
.as_json
render json: json_date
end
def fc_inicio(order_id, status_id = 3, role_id = 1)
OrderHistory.joins(:step)
.select('order_histories.start')
.where('steps.role_id' => role_id, 'steps.status_id' => status_id, 'order_histories.order_id' => order_id)
.where.not(end: nil)
.limit(1)
.to_json
end
Mano, use the merge() method according to: https://apidock.com/ruby/Hash/merge If the two methods return a json,at the end of one of the methods just put . merge (other-way-name). Remembering that if the two methods have keys of equal names, it will replace the old one with the new one being merged.
– Lougans de Matos