title: Use AngularJS to retrieve nested resource in Rails
body: <p>I have been working on implementing AngularJS into my Rails app based on the <a href="http://railscasts.com/episodes/405-angularjs" rel="nofollow noreferrer">Railscast</a> as a starting point. My question is similiar to this question: <a href="https://stackoverflow.com/questions/15058472/angular-js-ngresource-with-nested-resources">Angular JS ngResource with nested resources</a>, however I have not found a solution to my problem.</p>
  
  <p>Currently I have a nested resource which I am displaying on the view of the parent resource, via a partial. I need to supply the project_id in the query in order to retrieve the tasks, so I have:</p>
  
  <pre><code>app.factory "Task", ["$resource", ($resource) -&gt;
    $resource("/projects/:project_id/tasks/:id", {project_id: "@project_id", id: "@id"}, {update: {method: "PUT"}})
  ]
  
  @TaskCtrl = ["$scope", "Task", ($scope, Task) -&gt;
    $scope.tasks = Task.query({project_id: "@project_id", id: "@id"})
  </code></pre>
  
  <p>My question is, how do I set '@project_id' in the view so that on the last line in my example the value is accessible in the controller? I tried using ng-init:</p>
  
  <pre><code>&lt;div ng-controller="TaskCtrl" ng-init="project_id = &lt;%= @project.id %&gt;"&gt;
  </code></pre>
  
  <p>However once in my TaskCtrl controller 'project_id' is blank, and '$scope.project_id' does not work either. Any help is appreciated.</p>