Here is the scenario. 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 Has anyone done this? Gracias Jeff -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jeff, I haven''t done this but it doesn''t sound too hard. 1) Write a js snippet that fires off a call to a a custom controller action - let''s call it check_user_attribute(). 2) Wire this snippet up with the onblur event handler of form''s fields. 3) In check_user_attribute, build user and check valid?, then check errors on ''fieldname''. Update field as needed depending on outcome via rjs. Note that this is resource-intensive with all the remote calls and running the full validation every time a user changes fields. -- Zack Chandler http://depixelate.com On 4/4/07, RJ <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Here is the scenario. > > 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 > > Has anyone done this? > > Gracias > > Jeff > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> Note that this is resource-intensive with all the remote calls and > running the full validation every time a user changes fields. > > -- > Zack Chandler > http://depixelate.comThat 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---