1

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

2 Answers 2

1

Check the output of getAccountByEmail when you give it a known address and when you give it a new email address via the rails console. For it to always return true, your variable account has to be false or nil. That's where I would start.

Sign up to request clarification or add additional context in comments.

Comments

1

Not sure it this exactly helps you(sorry for that), but surely worth a shot. However, do proceed first as specified in the solution by Vincent. The value of account might be the issue.

Have you checked this gem for client side validations. Its at https://github.com/bcardarella/client_side_validations Its easy to use and you dont even need to write your own js.

There's a railscast on it too http://railscasts.com/episodes/263-client-side-validations

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.