N
N
Nikolai Markov2014-10-17 11:19:53
Java
Nikolai Markov, 2014-10-17 11:19:53

How to parse json with errors for nested model from Rails in Android?

There is a model

class User 
  has_one :profile
  accepts_nested_attributes_for :profile
end

When we try to update the profile via user.update({ profile_attributes: { ... }) and pass incorrect profile parameters (let's say we didn't specify the name that is stored in the profile), the server returns errors like this:
{
  'errors': {
    'user.profle': {
       'name': [ 'не может быть пустым']
     }
  }
}

Of course, I would like the rail to give such an answer
{
  'errors': {
    'user': {
       'profle': {
         'name': [ 'не может быть пустым']
       }
     }
  }
}

But for this you need to climb into the insides of the framework.
The question is how to parse the first option so that the resulting objects have the same structure as in the second json. Perhaps there is some way to tell the parser that the fields with a dot should be treated as a nested object?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Entelis, 2014-10-17
@DmitriyEntelis

Loop through the resulting data structure and form a new data structure.
I don't understand what the problem is.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question