R
R
Robert2016-08-28 23:12:48
Angular
Robert, 2016-08-28 23:12:48

How to convert for saving the data coming from the client side?

There is an API in the form of a rail application, and a client application in Angular.js.
Should I strive to achieve a state where data from the client comes 1 to 1, as needed, without the need for their mapping.
If not, then how to transform it so that it is DRY and generally beautiful?
Suppose a hash comes from the client containing the following data:
{
"name": "sample',
"tags": [
"non",
"adipisicing",
"deserunt",
"nulla",
"do",
"aute",
" enim"
]
}
On the client, you have to do something like:

AR::Transaction do
 if record.save
    tags.each do {|tag| record << tag.find_or_create_by(tag)}
 end
end

You can make some simple Form object.
What is the best approach to use? Or still try and add 1k1 data mapping?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Leontiev, 2016-08-29
@madmatvey

Using, for example, Postgres and JSONB , you can save any hash and access the structures inside it as you like. Is this what your question is about?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question