title: Authentication error using Rails - Devise and AngularJS
body: <p>I am using Devise for user authentication in a Rails application. I tried to use AngularJS instead of the default rails scaffolding in an application. The problem is that when I add the before_filter :authenticate_user! in the controller then AngularJS calls to update/save and delete a resource does not work saying Unauthorized Access (401). Here is some of the code:</p>
  
  <p>The resource:</p>
  
  <pre><code>@app.factory "employeesDB", ($resource) -&gt;
    $resource("/employees/:id", {id: "@id"}, {update: {method: "PUT"}},
      {destroy: {method: "DELETE"}}
    )
  </code></pre>
  
  <p>The save action:</p>
  
  <pre><code>  $scope.saveEmpl = -&gt;
      $scope.em = new Object if !$scope.em
      employeesDB.save({}, $scope.em, (resource) -&gt;
        $scope.employees.push(resource)
      , (response) -&gt;
        console.log("Failed")
      )
  </code></pre>
  
  <p>$scope.em is the object containing the data for the record and it is bind to angular using ng-model.</p>
  
  <p>Everything works perfect if I remove the before_filter :authenticate_user! from the controller</p>
  
  <pre><code>class EmployeesController &lt; ApplicationController
    #before_filter :authenticate_user!
  </code></pre>
  
  <p>The problem occurs only when I try to save/update/delete the record, just reading it works OK.</p>
  
  <p>Any ideas?? Are there any specific guidlines I should follow when using Angular and Devise?
  I am newbie to rails and angularJS so a detailed explanation will be greatly appreciated!
  Thanks</p>