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 7735749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:34:43+00:00 2026-06-01T07:34:43+00:00

Consider the below situation I have a database table as below user_id user_rank ——————

  • 0

Consider the below situation

I have a database table as below

user_id user_rank
------------------
22       10
32        9
43        7
31        6

and i have a JSON Object with the user id like (other nodes in json are hidden for simplicity, consider this response is from an api)

{"user_id":[31,22,43,32]} 

now, how do i sort the JSON result based on the rank of a user_id in database and produce a
result like

{"user_id":[22,32,43,31]}

is there anything like LINQ in rails, so that i can save the json object values in it,
and make join between the object and database table to obtain the sorted json?

  • 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-01T07:34:44+00:00Added an answer on June 1, 2026 at 7:34 am

    If you have user ids in json then :

    require 'json'
    user_hash = JSON.parse('{"user_id":[31,22,43,32]}') => {"user_id"=>[31, 22, 43, 32]}
    
    users = User.all(:conditions=>["id in ?",user_hash[:user_id]])
    sort_user_id = users.sort { |x, y| (x.user_rank|| 0 )<=> (y.user_rank|| 0)}.map(&:id)
    {:user_id => sort_user_id}.to_json
    

    Hope that help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table like below Consider the table id=testtable, and there is no
Consider a situation we have two variables in SQL Server 2005's SP as below,
In the code below, I have a while(true) loop. Consider a situation where there
Let's consider the below example. There, I have: target MAIN calls target t and
Consider the code below, private void Convert_Click(Object sender, RoutedEventArgs e) { string[] strCmdLineParams =
Consider the below table sample_table id name desc ------------------------- 1 kkt kkt description 1
Consider the following situation. I have 3 tables in a resource planning project(created using
Consider the below table ID Data Date 1 A 7/19/2011 1 A 6/12/2011 2
Here is the situation: I have a database of 'tickets', and we track changes
virtual function resolution happens with pointer/reference and not with object. Now consider below example:

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.