PeopleController
def valid_member?(member_number)
member_number = params[:number]
member = People.find(number: member_number)
if People.exists?(member)
render :status => 200, :nothing => true
else
render :status => 404, :nothing => true
end
end
routes.rb
match "/valid_member" => "people#valid_member"
application.js or people.js
function checkValidMember() {
$("input#member-number").data("oldVal", $("input#member-number"));
$("input#member-number").bind("propertychange keyup input paste", function(event){
if ($(this).data('oldVal') != $(this).val()) {
$(this).data('oldVal', $(this).val());
if ( isValidMember($(this).val()) ) {
alert("success");
// your jquery magic for success case goes here
}
else {
alert("fail");
// your jquery magic for failure case goes here
}
}
});
}
function isValidMember(member_number) {
$.ajax({
url: "valid_member?number="+member_number,
success: function(data) {
return true;
},
statusCode: {
404: function() {
return false;
}
}
});
}
first edit.
Obviously, you need to have input field with correct id, member-number, as the javascript i wrote above.