title: AngularJS form data to Ruby on Rails API
body: <p>I created a simple API with Ruby on Rails,and I'm trying to send data from a form with AngularJS. The thing is that the App is sending the post method and the backend is creating the new records, so far it's working, but it creates it with Null values.</p>
  
  <p>This is the form:</p>
  
  <pre><code>&lt;div ng-controller="postController"&gt;
      &lt;form name="messageForm" ng-submit="submitForm()"&gt;
          &lt;div class="form-group"&gt;
              &lt;label&gt;Name&lt;/label&gt;
              &lt;input type="text" name="content" class="form-control" ng-model="message.content"&gt;
          &lt;/div&gt;
          &lt;button type="submit" class="btn btn-primary"&gt;Submit&lt;/button&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This is the Angular Controller:</p>
  
  <pre><code>app.controller('postController', function($scope, $http) {
    // create a blank object to handle form data.
      $scope.message = {};
    // calling our submit function.
      $scope.submitForm = function() {
  
      $http({
        method  : 'POST',
        url     : 'http://localhost:3000/api/v1/messages',
        data    : $scope.message, //forms user object
        headers : {'Content-Type': 'application/x-www-form-urlencoded'} 
       })
        .success(function(data) {
          if (data.errors) {
            // Showing errors.
            $scope.errorContent = data.errors.errorContent;
          } else {
            $scope.message = data.message;
          }
        });
      };
  });
  </code></pre>
  
  <p>And in the RoR's API Controller, this is the Create method:</p>
  
  <pre><code>def create 
      respond_with Message.create(params[:message])
  end
  </code></pre>
  
  <p>The only rows are:</p>
  
  <ul>
  <li>ID which is generated automatically.</li>
  <li>And 'content'</li>
  </ul>