I have this problem : I\'m checking user email in controller and sending json successfull response if it is already taken and add css styling of input, also I need to prevent su
I would do it like this:
$('#element').focusout(function() {
$.getJSON('PATH_TO_EMAIL_CHECK_ACTION', { email: $('#element').val() }, function(data) {
// The data should tell you if its unique or not, you do something
// here depending on response
});
});
And in the controller, check if the email is taken. If its not, send back render json with status OK and message success. You can check if the status is success in your callback where the comment is above.
jquery focusout - http://api.jquery.com/focusout/
jquery getJSON - http://api.jquery.com/jQuery.getJSON/
About json responses in controller - http://paydrotalks.com/posts/45-standard-json-response-for-rails-and-jquery