Rails 5 validate CPF

1

Hello, I'm new to RoR. I have a form with field for CPF and I need to validate whether it is valid or not before saving the record.

I tried different gems like gem'cpf_cnpj, gem 'brcpfcnpj' and 'validates_cpf_cnpj', but following the readme in github, they all gave some sort of error, perhaps due to the compatibility of ruby or rails.

My last attempt was to use a ruby code and create a custom validate, but I was not successful either.

Does anyone have a solution using Rails 5?

    
asked by anonymous 26.09.2017 / 23:16

1 answer

1

Using the gem: CPF / CNPJ

Watch out for the use of require

I used it to test with Rails 5.0.6 and ruby 2.3.1p112

The same worked perfectly, you can use other gems as well.

You can use the callback features and validate before saving before_save data.

link

    
02.10.2017 / 22:44