我有一个Rails / Angular应用程序,带有工厂。
Rails应用程序正确运行第一个get,但由于某种原因,数据没有回到Angular应用程序。同样的查询来自api。
angular.module('assaypipelineApp').factory 'Primer3Output', ($resource) ->
$resource('/api/batch_details/:batch_detail_id/primer3_output',
{batch_detail_id: '@batchDetailId'},
{update: {method: 'PATCH'}})
angular.module('assaypipelineApp').factory 'Primer3OutputPair', ($resource) ->
$resource('/api/primer3_outputs/:primer3_output_id/primer3_output_pairs',
{primer3_output_id: '@primer3OutputPairId'},
{update: {method: 'PATCH'}})
的routes.rb
resources :batch_details do
resource :primer3_parameters
resource :primer3_output
end
resources :primer3_outputs, only: [:show, :update] do
resources :primer3_output_pairs, only: [:index, :update]
end
角度控制器
$scope.invokeAssayModal = (assay_id) ->
$scope.assay_id = assay_id
$scope.primerPairs = {}
$scope.primer3Output = Primer3Output.get({batch_detail_id: $scope.assay_id})
console.log("xxx1")
console.log(JSON.stringify($scope.primer3Output,null,' '))
console.log($scope.primer3Output.id)
console.log("xxx2")
$scope.primerPairs = Primer3OutputPair.query({primer3_output_id: $scope.primer3Output.id})
console.log("xxx")
console.log(JSON.stringify($scope.primerPairs,null,' '))
控制台输出
] PanelController.js?body=1:178
xxx1 PanelController.js?body=1:380
{} PanelController.js?body=1:381
undefined PanelController.js?body=1:382
xxx2 PanelController.js?body=1:383
xxx PanelController.js?body=1:387
[] PanelController.js?body=1:388
Rails控制台
Started GET "/api/batch_details/15337/primer3_output" for 127.0.0.1 at 2014-02-27 21:33:29 +0100
Processing by Api::Primer3OutputsController#show as JSON
Parameters: {"batch_detail_id"=>"15337"}
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
BatchDetail Load (0.3ms) SELECT "batch_details".* FROM "batch_details" WHERE "batch_details"."id" = $1 LIMIT 1 [["id", "15337"]]
Primer3Output Load (0.3ms) SELECT "primer3_outputs".* FROM "primer3_outputs" WHERE "primer3_outputs"."batch_detail_id" = $1 ORDER BY "primer3_outputs"."id" ASC LIMIT 1 [["batch_detail_id", 15337]]
Completed 200 OK in 6ms (Views: 1.6ms | ActiveRecord: 1.1ms)
Started GET "/api/primer3_outputs/primer3_output_pairs" for 127.0.0.1 at 2014-02-27 21:33:29 +0100
Processing by Api::Primer3OutputsController#show as JSON
Parameters: {"id"=>"primer3_output_pairs"}
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
Completed 404 Not Found in 2ms
ActiveRecord::RecordNotFound - Couldn't find BatchDetail without an ID:
通过浏览器API
这些返回带有正确数据的json对象,因此api正在工作。
http://0.0.0.0:3000/api/batch_details/15337/primer3_output
http://0.0.0.0:3000/api/primer3_outputs/412/primer3_output_pairs