views:

30

answers:

2

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

A: 

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!

Larry K
A: 

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

Elad Meidar
Yeah, I was looking for something like this. Thanks
sparrovv