sparrovv
sparrovv

Reputation: 7784

Javascript validation using activerecord models validators

I have an activerecord model and set of validators to it, But I also have to provide front end validation.

Is there a gem or a smart way to use activerecord validators, for instance in jquery validation plugin, instead of writing it by hand?

Thanks

Upvotes: 4

Views: 1593

Answers (3)

onurozgurozkan
onurozgurozkan

Reputation: 1794

You can check client_side_validations

Regards.

Upvotes: 1

Elad Meidar
Elad Meidar

Reputation: 814

No need to duplicate the costs. There are some gems/plugins around that duplicate the Model's validations in the client side. yes, you'll have to do some client-side customizations still, but it should be very easy.

here's an example of such plugin: http://github.com/grimen/validatious-on-rails

Upvotes: 0

Larry K
Larry K

Reputation: 49114

Jquery has a validation library. Plus there are many others too. Google for Javascript form validation.

Unfortunately, some validations require more access to the business rules of your app in your browser/JS code. So you'll then have to weigh the costs of duplicating business logic in your JS vs the benefit of the immediate feedback to the user.

Just be sure not to skimp on implementing your business rules (and testing them) in your server-side sw first. Remember that clients can never be trusted--even the clients that you write yourself!

Upvotes: 0

Related Questions