I recently wrote a new gem called realtime-validations. It is now
covering our use case, but it sure can be improved, and I will
personally improve and maintain it if there are unmet needs for any of
- Validate user input at client-side
- Never, ever replicate logic.
- Why this gem ? We already have at least the great
client-side-validations gem !
- We like client-side-validations gem, however we believe that there
is a 'even better' way to handle client side validations.
- If you have a simple model in which you have simple validations
(length, presence, even uniqueness...) client-side-validations will
serve you well. However, things start to become hard if you have
custom validators that do really strange fu, or if you have, for
example, a :uniqueness scoped by user_id. Realtime-validations comes
to fix this issues.
- On complex (and probably strange) validations you need to
to maintain, and someone can forget to update one or the other.
Replicated logic in two different languages is not the best way to go.
Also you would need to jump over language specific issues.
- How is it done ?
- Each time the user blurs a field (that is, focuses out a field), a
request is sent to a special controller, that will create (or find a
model), set the edited property and validate the model. The errors of
that field are then sent back to the client.
- You only have validations on your model, where it should be. It
does not matter how strange or complicated they are, they are just
issued without problems.
- You can also send to the server special information as which is
the current user or similar stuff, so the model will set this
information before setting the edited field and validate it.
Validations with :uniqueness :scoped_by => :user_id will work nicely.
So please, if you need something else that should be achieved I would
be happy to know about it.
Rafael Fernández López
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to firstname.lastname@example.org.
To unsubscribe from this group, send email to email@example.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.