Last active
August 29, 2015 14:10
-
-
Save mahm/7deb7549a8f50ec5a073 to your computer and use it in GitHub Desktop.
AngularJS + Railsでネストしたリソースを取得する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProjectsController < ApplicationController | |
def index | |
@projects = Project.all | |
end | |
def show | |
@project = Project.find(params[:id]) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="col-md-12"> | |
<h2><%= @project.title %></h2> | |
<div ng-app="tasksApp" ui-view="" ng-init="projectId = <%= @project.id %>"> | |
</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
angular.module('tasksApp') | |
.controller('TasksController', ['$scope', 'Task', function($scope, Task){ | |
$scope.currentTasks = Task.currentTasks({project_id: $scope.projectId}); | |
$scope.iceboxTasks = Task.iceboxTasks({project_id: $scope.projectId}); | |
}]) | |
; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
angular.module('tasksApp') | |
.provider('Task', function () { | |
this.$get = ['$resource', function ($resource){ | |
var Task = $resource('/api/projects/:project_id/tasks/:id.json', { id: '@id', project_id: '@project_id' }, { | |
currentTasks: { method: 'GET', isArray: true, params: { task_type: 'current' }}, | |
iceboxTasks: { method: 'GET', isArray: true, params: { task_type: 'icebox' }}, | |
update: { method: 'PUT' } | |
} | |
); | |
Task.prototype = { | |
}; | |
return Task; | |
}]; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment