I'm working with a Rails server (with Devise for authentication) and an AngularJS client. I've added a form generated by Rails to my client-side page, adding the ng-submit Angular directive like so:
<%= form_for("user",
:url => user_session_path,
:html => { "ng-submit" => "doSignIn()" }) do |f| %>
This generates a form with both action and ng-submit attributes, like this:
<form accept-charset="UTF-8" action="/users/sign_in" method="post" ng-submit="doSignIn()">
In the definition of the controller in the enclosing div, I have a doSignIn function that doesn't do anything at the moment:
$scope.doSignIn = function() {
console.log($scope.email, $scope.password);
};
$scope.email and $scope.password are bound using ng-model. Or, at least, they're supposed to be - I can't tell, because clicking on submit always results in being directed to /users/sign_in. I was under the impression that using ng-submit would prevent the form from redirecting the user. I have also tried adding an ng-click to the submit button, using the same method, which also uses the doSignIn() method, and I've even tried passing it the event and calling event.preventDefault(). Nothing seems to stop me being redirected.
My goal is eventually to perform sign-in with AJAX, but for now, just proving that I can stop the automatic redirect would be great!