V
V
Vayladion Gognazdiak2015-04-15 10:10:45
Ruby on Rails
Vayladion Gognazdiak, 2015-04-15 10:10:45

How to properly organize data sampling and serialization ( RoR )?

Good day.
There is a users table:
id,name,created_at,updated_at
It is required by means of AR to make a certain selection and give it to json.
There are no problems with turning it into json - @users = User.all.as_json , the problem arises in the specifics of the selection. Requires users to be grouped by creation date ( created_at ).
In other words, the sample should look something like this:

"created_at" => [
     "2015-01-01" => {
      "users" => [ { "id" => 1, "name" => "Ivan"},
              { "id" => 2, "name" => "Sergey"] }
      "2015-01-12" => {
      "users" => [ { "id" => 3, "name" => "Ivan"},
              { "id" => 4 "name" => "Sergey"] }
]

Smoking mana, alas, does not give an answer, and making a bunch of requests is expensive.
Thanks in advance for your reply.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question