Forums » Ruby on Rails » Check a username availablity - the AJAX way

Ok, if you want to check whether a username(or any other field) is available or NOT using rails while you type the text in the textbox, just add the below code

<%= observe_field(:user_username,:url => { :action => :check },:frequency => 0.5, :update=>'checker',:with => "'user[username]=' + $F('user_username')",:before=>"'loading')",:success=>"Element.hide('loading')") %>

:user_username - is the id for the text field.
:action - is to which action to send the request
:frequency - may be set to 0.5 ( will not work if you don't set this)
:update - is the DIV-ID for the DIV to be updated.
:with - live data which you want to send
:before and :after are to handle the loading image.

Then, just add the action in your controller and you are ready to go!