# REST and AJAX Validators

**URL:** <https://www.ruby-forum.com/t/rest-and-ajax-validators/88799>\
**Category:** Rails\
**Created:** [March 14, 2007, 3:02pm UTC](https://www.ruby-forum.com/t/rest-and-ajax-validators/88799 "2007-03-14T15:02:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fluffy\_Hippo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/f475e1/32.png) [@Fluffy\_Hippo](https://www.ruby-forum.com/u/Fluffy_Hippo)\
**Post date:** [March 14, 2007, 3:02pm UTC](https://www.ruby-forum.com/t/rest-and-ajax-validators/88799/1 "2007-03-14T15:02:03Z")

</div>

So what’s the ‘right’ way to deal with AJAXY validators under REST?

Say I have an observe\_field that checks against taken usernames, where  
do I  
stick the available\_user method? … it doesn’t seem to fit in the  
RESTful  
user\_controller, do I just create another controller to store all my  
AJAX  
cruft that is non-REST, or is there a more  
official/sanctioned/opinionated  
way to do this?

---

<div class="post-metadata">

**Author:** ![Fluffy\_Hippo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/f475e1/32.png) [@Fluffy\_Hippo](https://www.ruby-forum.com/u/Fluffy_Hippo)\
**Post date:** [March 14, 2007, 5:15pm UTC](https://www.ruby-forum.com/t/rest-and-ajax-validators/88799/2 "2007-03-14T17:15:25Z")

</div>

On Wednesday 14 March 2007, Fluffy Hippo wrote:

> So what’s the ‘right’ way to deal with AJAXY validators under REST?

Put them in the controller that handles the resource.

> Say I have an observe\_field that checks against taken usernames,  
> where do I stick the available\_user method? … it doesn’t seem to  
> fit in the RESTful user\_controller,

REST is a guideline, not a straitjacket.

Michael

–  
Michael S.  
[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.schuerig.de/michael/](http://www.schuerig.de/michael/)

---

<div class="post-metadata">

**Author:** ![Fluffy\_Hippo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/f475e1/32.png) [@Fluffy\_Hippo](https://www.ruby-forum.com/u/Fluffy_Hippo)\
**Post date:** [March 14, 2007, 5:32pm UTC](https://www.ruby-forum.com/t/rest-and-ajax-validators/88799/3 "2007-03-14T17:32:27Z")

</div>

On Mar 14, 9:01 am, “Fluffy Hippo” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> So what’s the ‘right’ way to deal with AJAXY validators under REST?
> 
> Say I have an observe\_field that checks against taken usernames, where do I  
> stick the available\_user method? … it doesn’t seem to fit in the RESTful  
> user\_controller, do I just create another controller to store all my AJAX  
> cruft that is non-REST, or is there a more official/sanctioned/opinionated  
> way to do this?

What would available\_user do? My guess is, given a potential user  
name, see if a user with than name already exists, right?

In that case, perhaps your ajax call would just call [myapp.com/users](http://myapp.com/users)?  
name=‘potential\_name’ and see if you get a 404 back (no user found) or  
a 200 (which could mean that the user was found).

This way you’re still RESTful, just look for query parameters that  
help refine your query.

Would that work?

Jeff

> **[Hey Daddio!](http://softiesonrails.com)**
>
> Home of Hey Daddio Software
