Reputation: 1399
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
});
Upvotes: 1
Views: 591
Reputation: 2324
Take a look at validates_uniqueness_of in the API documentation
Upvotes: 1
Reputation: 5352
What do you mean by JSON format and if you like to use some sort of validation. I recommend using Railscasts
Upvotes: 1