I’m working on ruby on rails and i’m an absolute beginner.
My question is:
I have a user signup form and I would like to verify whether the username already exists and return the status in json format. I would like to achieve this by using the jquery ajax, how do i do this.
def check_user
@user=User.find_by_username(params[:username'])
respond_to do |format|
format.html
format.json { render json: !@user }
end
end
my application.js:
$("#user_name").change(function(){
//How do i call my check_user action and get a response
});
Take a look at validates_uniqueness_of in the API documentation