Rails client-side validation method (Rails 4 with simple_form)

I am new to Rails and use Rails 4. I started creating some forms to create / edit some models and added some validations that work fine on the server side.

I assumed that Rails will have something built-in to handle client-side validation - it turns out that it doesn't.

I searched on google and found "client_side_validation" which is no longer supported, and I generally don’t think it works in Rails 4.

There seems to be no obvious transition to the library for client-side Rails validation. So what is the “Rails way” to handle this? Drop yours? Duplicate logical client side using jQuery? Use html5 validation and go back to the server side if it’s not theirs? Or is there a library (preferably one that works with simple_form) that I can just install and use?

+4
source share
4 answers

There is client_side_validations , but is no longer supported. Probably the best way is to use some jQuery plugin like jquery-validation .

+2
source

Rails 4 + : " " simple_form , , Github .

Rails >= 4.0

gem 'client_side_validations', github: 'DavyJonesLocker/client_side_validations'
gem 'client_side_validations-simple_form', github: 'DavyJonesLocker/client_side_validations-simple_form'

, gem

client-side Validation 3.2.5
client_side_validations-simple_form 2.1.0

4.2.0

, , , https://github.com/DavyJonesLocker/client_side_validations-simple_form/issues/41

+2

I was able to use the fork of the original client_side_vlaidations, which is very active at the moment. I am using the latest version of simple_form, rails 4.1.8 and client_side_validations . Easy setup with basic configuration.

0
source

All Articles