How to make AngularJS check and use data on the Rails backend?

Like say I wanted to make sure someone signing up did not use a pre-existing email address. How to make the AngularJS file interact with the Rails user model/users database to see that? Is NodeJS necessary here? Can this be done with a "unique" directive (the approach I wish to follow)?

I am using the 1.3.0-beta.18 version of AngularJS. I don't know how that changes things - is the $parse function still used? How does one setValidity using the $validators pipeline?

EDIT: I came across this example from http://www.ng-newsletter.com/posts/validations.html. How do I adapt it to a typical Rails setup - Users controller, User model and users database? What if I have a "unique" method in the Users controller that queries the User model to see if there is an entry with that email parameter? This "unique" method is called by the "unique" AngularJS directive, and the directive is called in the sign up form. I do already have a "unique" JSON route appearing when I do "rake routes", as well as a "unique" HTML route. I know how to call directives in the form and how to do error checks in the form, so that is not an issue.

app.directive('ensureUnique', ['$http', function($http) {
  return {
    require: 'ngModel',
    link: function(scope, ele, attrs, c) {
      scope.$watch(attrs.ngModel, function() {
        $http({
          method: 'POST',
          url: '/api/check/' + attrs.ensureUnique,
          data: {'field': attrs.ensureUnique}
        }).success(function(data, status, headers, cfg) {
          c.$setValidity('unique', data.isUnique);
        }).error(function(data, status, headers, cfg) {
          c.$setValidity('unique', false);
        });
      });
    }
  }
}]);

LATEST EDIT 8/29/2014: So this is the code I am working with, but it does not work. Form submission is great with the FormCtrl controller and User factory, but the UniqueEmail factory and EnsureUnique directives don't work. All the standard AngularJS directives (like ng-minlength) are working fine in the HTML form.

I have the Rails routes api/users/unique and users/unique. I am not quite sure which is used, I assume api/users/unique?

This is my Rails controller method 'unique' code:

class UsersController < ApplicationController
include AngularController



def new
  @user = User.new
  respond_with @employee
end

def create
        @user = User.create(params.permit(:email, :name, :password,  :password_confirmation))
        if @user.save
        session[:@user_id] = @user.id
        redirect_to root_url
        else
        render 'new'
        end

end 
def unique
if User.exists?(:email => params[:email])
return true
end
end
end

module AngularController
  extend ActiveSupport::Concern

  included do
    respond_to :html, :json
    around_action :without_root_in_json
  end

  def without_root_in_json
    ActiveRecord::Base.include_root_in_json = false
    yield
    ActiveRecord::Base.include_root_in_json = true
  end
end

This is my AngularJS code:

     mainapp.factory("UniqueEmail", function($resource) {
     return {
      states: $resource('/users/unique.json', {}, {
        query: { method: 'GET', params: {}, isArray: false }
      })
    };
  });

mainapp.factory("User", function($resource) {
  return $resource("/users/:id", {
    id: "@id"
  });
});


app.directive('ensureUnique', ['$http', function($http) {
  return {
    require: 'ngModel',
    link: function(scope, ele, attrs, c) {
      scope.$watch(attrs.ngModel, function(value) {
        $http.get({
          url: '/users/unique',
          params: {"email": value}
        }).success(function(data, status, headers, cfg) {
          c.$setValidity('unique', false);
        }).error(function(data, status, headers, cfg) {
          c.$setValidity('unique', true);
        });
      });
    }
   }
}]);

mainapp.controller("FormCtrl", function($scope, User, UniqueEmail) {
  $scope.user = new User();
  $scope.users = User.query();
  $scope.password_confirmation = null;

  $scope.add = function() {
  $scope.users.push(User.save({
  name: $scope.user.name,
  email: $scope.user.email,
  password: $scope.user.password,
  password_confirmation: $scope.user.password_confirmation
  }));
  return $scope.user = new User();
  };
  return $scope["delete"] = function($index) {
   if (confirm("Are you sure you want to delete this user?")) {
  $scope.users[$index].$delete();
  return $scope.users.splice($index, 1);
  }
  };
  });

just make angular-request through $http, and provide the rest-endpoint in your rails-app.

ideally you use something like $resource or restangular, because usually you want to make some CRUD operations, and that's where rails is a good fit.

another option is to use it with Angular Rails Templates. here is a good post, on how to do this. this link was also published with one of the last ng-newsletters