title: How to bootstrap data as it it were fetched by a $resource service in Angular.js
body: <p>I have this Rails app that serves an index.html.erb by a UsersController. In the angular controller that handles that page, I have a $resource service for the User</p>
  <h1>CoffeeScript</h1>
  <pre><code>.factory('User', ['$resource', ($resource) -&gt;
    $resource 'api/users/:user_id/:action', {authenticity_token:app.csrf},
      query:
        method: 'GET'
        isArray: yes
      new:
        method: 'GET'
        params:
          user_id: 'new'
      update:
        method: 'PUT'
  ])
  </code></pre>
  <p>And the controller fetches</p>
  <pre><code>window.app = angular.module(&quot;app&quot;, ['userServices'])
  .config([&quot;$routeProvider&quot;, ($routeProvider) -&gt;
    $routeProvider
    .when &quot;/users&quot;,
      templateUrl: &quot;assets/templates/users/index.html&quot;
      controller: UserCtrl
      
    .otherwise redirectTo: &quot;/users&quot;
  ])
  
  # users Controllers
  UserCtrl = ($scope, User) -&gt;
    User.query (r) -&gt;
      $scope.users = r
      # code..
  </code></pre>
  <p>I think this is a pretty common scenario, but clearly it takes more than one trip to the server for just this page. I was wondering if there's a way for Angular to use some bootstrap data as it they were returned data from an action called in a $resource service.</p>
  <p>I have already taken care of the bootstrap data part by assigning it to a global variable called Gon with the Gon ruby gem. I know I could simply do $scope.users = gon.users. But then these users models won't get the niceties like $scope.users[0].$save()</p>
  <p>Thank you!</p>