Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7875263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:57:13+00:00 2026-06-03T02:57:13+00:00

I tried to render the data from my database to_json like this, it works

  • 0

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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:57:14+00:00Added an answer on June 3, 2026 at 2:57 am
      def updateStatus
        order = JSON.parse(params["updateStatus"])
        @item = OrderItem.where(order_batch_id: order["batchId"], item_id: order["itemId"])
        status = order["status"]
        case status
          when "cancelled"
            @item.first.update_attributes(cancelled: order["statusTime"])
          when "accepted"
            @item.first.update_attributes(accepted: order["statusTime"])
          when "cooking"
            @item.first.update_attributes(cooking: order["statusTime"])
          when "ready"
            @item.first.update_attributes(ready: order["statusTime"])
          when "delivered"
            @item.first.update_attributes(delivered: order["statusTime"])
        end
        render json: @item.to_json(except: [:created_at, :updated_at], message: "success")
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to read data to a list from database. I tried the following
I have a doubt i use the following piece of code get data from
I faced the error when I tried to capture the POST data from a
Today i tried changing a users role from db owner to db data reader
I've got an ASP.NET ashx class that retrieves data from a database, creates a
i am getting funny data records like & whenever i tried export data records
I'm using MySQL Connector to retrieve data from a mySQL database to a .NET
In my index.html.erb page when data is queried from MSSQL it get displayed as
I have tried mupdf library to render my pdf ie. to have my own
Tried this: $('.link').click(function(e) { $.getScript('http://www.google.com/uds/api?file=uds.js&amp;v=1.0', function() { $('body').append('<p>GOOGLE API (UDS) is loaded</p>'); }); return

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.