title: Rails 4 Angularjs Paperclip how to upload file
body: <p>I'm novice to manipulate angularjs with Rails 4 which provide only api's. I try to create  a simple angular service to upload a file. But I use Paperclip to manage file and I have some issues.</p>
  
  <p>First, I don't understand how to collect properly the file of the input. I have see a lot of plugin or fat directive to do that. But i want juste a simple directive that collect my file and put in my ng-model.</p>
  
  <p><strong>And finally I want to know if it is more efficient to encode my file in Base64 ?</strong></p>
  
  <p>My Rails controller</p>
  
     <pre class="lang-ruby prettyprint-override"><code>class Api::EmployeesController &lt; Api::BaseController
    def create
      employee = Employee.create(employee_params)
      if employee.save
        render json: employee
      else
       render :json =&gt; { :errors =&gt; employee.errors.full_messages }, :status =&gt; 406
       end
    end
  
    def employee_params
      params.require(:employee).permit(:first_name,:mobile_phone,:file)
    end
  end
  </code></pre>
  
  <p>My Angularjs Service</p>
  
     <pre class="lang-coffee prettyprint-override"><code>angular.module('test').factory 'Employee', ($resource, $http) -&gt;
   class Employee
    constructor: (errorHandler) -&gt;
    @service = $resource('/api/employees/:id',
    {id: '@id'},
    {update: {method: 'PATCH'}})
    @errorHandler = errorHandler
  
    create: (attrs, $scope) -&gt;
      new @service(employee: attrs).$save ((employee) -&gt;
        $scope.employees.push(employee)
        $scope.success = true
        $timeout (-&gt;
          $scope.success = false
        ), 3000
      ), @errorHandler
  </code></pre>
  
  <p>My Angularjs Controller</p>
  
     <pre class="lang-coffee prettyprint-override"><code>angular.module('test').controller "EmployeesController", ($scope, $timeout,  $routeParams, $location, Employee) -&gt;
  
  $scope.init = -&gt;
   @employeeService = new Employee(serverErrorHandler)
   $scope.employees = @employeeService.all($scope)
  
  $scope.createEmployee = (employee) -&gt;
    if $scope.employeeFirstName
      @employeeService.create (
        first_name: $scope.employeeFirstName
        last_name:     $scope.employeeLastName
        promotion: $scope.employeePromotion
        mobile_phone: $scope.employeeMobilePhone
        nationality: $scope.employeeNationality
        social_number: $scope.employeeSocialNumber
        born_place: $scope.employeeBornPlace
        employee_convention: $scope.employeeConvention
        employee_type: $scope.employeeType
    ), $scope
    else
      $scope.error = "fields missing"
  </code></pre>