5

I have my form and validation working great with regular http requests. I would like it to use AJAX. I know i can validate on the client side but that seems redundant given that I have defined the validations in my model.

As the user is filling out the form, I'd like to give feedback to them on their entries. What is the best way to use the rails defined validations in an AJAX form and give live feedback?

chrishomer
  • 4,900
  • 5
  • 38
  • 52

5 Answers5

5

For Rails 3 check out Client Side Validations: https://github.com/bcardarella/client_side_validations

Here's the railscast: http://railscasts.com/episodes/263-client-side-validations

vansan
  • 762
  • 7
  • 17
5

Check out the live-validations plugin. There's also an introductory screencast.

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
  • Looks to be exactly what I need but when I script/plugin install it and add the option to the form for, I get an error when the server is booting: uninitialized constant LiveValidations Thoughts? – chrishomer Jul 20 '09 at 14:34
  • 3
    The GitHub repo says it is no longer maintained. Anyone know of a good replacement for rails 3? – Ivan -Oats- Storck Jan 12 '12 at 20:31
2

Live-validations was kinda messy to get working for me, so I started with my own solution from scratch backed by Validatious. It's actually really DRY because of the Rails conventions in the back that made it possible to do a lot of smart assumptions. In most cases, all you need is to include a few javascript dependencies and declare your validations in your models as always - and it all just works! =) Peep the README for details.

Here it is:

http://github.com/grimen/validatious-on-rails

grimen
  • 101
  • 4
  • 2
    It appears unmaintained, and not compatible with Rails 3. What project out there is current and widely used? I find it hard to believe that everybody does their home-grown one. – Wolfram Arnold Feb 22 '11 at 02:20
1

If you're looking for a solution to this that does not introduce any plugin dependencies check out my screencast on the issue:

AJAX Validations on Rails 2.3.8

Emerson
  • 536
  • 6
  • 9
0

https://github.com/augustl/live-validations/wiki has installation instructions.

When you add LiveValidations.use :jquery_validations to the bottom of your environment.rb, make sure it is outside of the Rails::Initializer block.

RamC
  • 1,287
  • 1
  • 11
  • 15