我正在使用Angular $资源编写自己的API控制器。使用1个资源渲染RAILS侧控制器上的所有对象,或者进行3次不同的资源调用是否更好。
app.factory("responseResource", function($resource) {
return $resource("/api/v1/responses/:id", {id: "@id" },
{
get: { method: "GET" },
update: { method: "PUT" }
});
});
class Api::V1::ResponsesController < Api::V1::ApiController
def show
@response = Response.find(params[:id])
@rubric = Rubric.find(@response.rubric_id)
@questions = @rubric.questions
render json: { response: @response, questions: @questions, rubric: @rubric }
end
end