A
A
aaltw2021-08-09 13:50:24
Ruby on Rails
aaltw, 2021-08-09 13:50:24

Why do I need a dry-rb validator in a rails application?

Just to avoid writing extra code in models?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
vsuhachev, 2021-08-10
@altw

If for some reason your input data and models do not match 1-in-1, then it is easier to validate the input data not through models, but with a separate vadidator, and then convert it into models. Such a validator can be written on ActiveModel, Dry, json-schema or something else, it's a matter of your preferences. They do not replace validations in the model, it is still better to write them (similarly with foreign keys, unique indexes and other restrictions at the database level).
So why dry? The dry approach has useful features, for example, types / schemas / structures are easy to reuse, they make it easier to check heavily nested data, you can set up checks more flexibly (compared to ActiveModel). Of the minuses, one can name the fact that it has not yet settled down, there are breaking changes. There is not always comprehensive documentation, the community is not as big as rails.

Z
Zaporozhchenko Oleg, 2021-08-09
@c3gdlk

dry-rb - dry-rb stack, i.e. answers to the question to use or not - like answers to the question about faith. Everyone with experience will decide for himself. If you haven't decided yet, then you don't have enough experience.
Do what the team does. If there is no command, then it is easier not to use it. If the project is educational - try this and that.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question