I am using the JQuery Validation plugin to validate a sign up form on my website.
I want to use a remote call to see if an email exists.
However, I am having difficulty.
The form keeps returning the message "Please enter a valid email address"
I have been following this tutorial: http://sleekd.com/tutorials/jquery-validation-in-ruby-on-rails/
Below is my code so far:
JS File
$(document).ready(function() {
$("#new_account").validate({
rules: {
"account[name]": {required:true},
"account[email]": {required:true, email:true, remote:"/check_email"},
"account[password]": {required:true},
"account[gender]": {required:true}
}
});
});
Route
match 'check_email/:email' => 'accounts#checkEmail', :as => :check_email
Controller
def checkEmail
account = Account.getAccountByEmail(params[:email])
respond_to do |format|
format.json {render :json => !account}
end
end
Appreciate any help.
Thank you,
Brian