These are chat archives for dry-rb/chat

19th
Apr 2017
vetcovetco
@vetcovetco
Apr 19 2017 00:41
Hello. I really like the look, feel, performance of dry-validation. I want to replace ActiveRecord with it. I have some questions about behavior I find odd. Here's a paste: https://gist.github.com/vetcovetco/ff6bab9f30ad8d954edfcaca6b135199
Also, I see that I can get an errors-object back via #call; is there a way to access the attributes-and-their-values, too? I want to use the DV object in an HTML form.
Oh, NM on that last question, I see ::Form and #result.
Er, #output.
vetcovetco
@vetcovetco
Apr 19 2017 01:11
Hrm. This isn't a drop-in replacement for AR or AM. Things like form_for wanting #model_name.
vetcovetco
@vetcovetco
Apr 19 2017 01:18
How can I get my form to show the values already present in the object?
Tim Riley
@timriley
Apr 19 2017 02:31
#to_h is probably better to use than #output, @vetcovetco. #output will disappear at some point. BTW, the result object also quacks a bit like a hash, so you can also just do result[:my_attr_name]
As for getting a rails form to work, if you don’t want to roll any of your own integration code, your best bet right now would be to use a gem like reform, which integrates with dry-v
Tim Riley
@timriley
Apr 19 2017 02:37
I think your rule should probably be something like this: required(:name).filled(min_size?: 1, max_size?: 64)
Pablo Herrero
@pabloh
Apr 19 2017 18:21
@vetcovetco, I'm think you are not suppose to define a field several times, since it will override all the previous definitions. Though you can put all your conditions on a single line like @timriley showed.