Standard web form that maps directly onto a model (Lets say “user”
model).
I want to add ajax validation so that when the user exits each field a
little request is fired off, the field is validated and if it doesn’t
then the error message is displayed above the field.
I don’t want to duplicate the validations setup in te model. What I want
is to validate the field against the respective validates_ rules in the
model that may or may not exist.
Can you call specific validations for a model? What I would envisage is
something like
controller:
def validate
returns error message if validation fails
result = User.validate_the_field(params[:field], params[:value])
render the result etc etc
end
That was my original plan but as yous said it is rather intensive and I
don’t like the idea of creating a new instance of a model and running
the full validation to just to check one field, I was hoping someone
much cleverer than me had writtena plugin or gem that does the
check_user_attribute stuff directly since this doesn’t seem like a
totally unique case.
I am still not liking the idea of creating a User.new, maybe I’ll be
crazy and delve into the validators themselves and see how they tick.
RJ
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.