I tried to render the data from my database to_json like this, it works well.
def getOrderDetails
#To get the details of a particular guest_order and its batches and items
@guest_order = GuestOrder.find(params[:id])
render json: @guest_order.to_json(except: [:created_at, :updated_at],
include: {order_batches: {except: [:guest_order_id, :created_at, :updated_at],
include: {order_items: {except: [:order_batch_id, :created_at, :updated_at] } }
}
}
)
end
But, I don’t know how to write a method to get a json data and parse it and then update into database.
If I send a json data from mobile like this,
Parameters:{"updateStatus" => "{\"itemId\":1,\"status\":\"accepted\",\"statusTime\":\"2012-04-25 18:28:30\",\"batchId\":5}"}
Here status is one of these accepted, cooking, ready, delivered, cancelled. statusTime is the value of the particular status.
How can I get this data and parse and then update into the following table in database
def updateStatus
# How to parse json and save in database
end
The table schema looks like this,
# == Schema Information
#
# Table name: order_items
#
# id :integer not null, primary key
# quantity :integer
# accepted :datetime
# cooking :datetime
# ready :datetime
# delivered :datetime
# cancelled :datetime
# order_batch_id :integer
# dish_id :integer
# created_at :datetime
# updated_at :datetime
#
Thanks in advance.
1 Answer