我正在尝试 Angular JS,我想从我的 rails 应用程序中定义的嵌套资源中获取数据。
我写了以下几行:
UserMission = $resource("/users/:user_id/user_missions/:id", {user_id: "@user_id", id: "@id"}, {update: {method: "PUT"}})
$scope.user_missions = UserMission.query()
我收到以下错误:
Processing by UsersController#show as JSON
Parameters: {"id"=>"user_missions"}
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", "user_missions"]]
Completed 404 Not Found in 10ms
ActiveRecord::RecordNotFound (Couldn't find User with id=user_missions):
app/controllers/users_controller.rb:100:in `current_resource'
app/controllers/application_controller.rb:34:in `authorize'
我的铁路路线是这样组织的:
resources :users do
resources :user_missions
end
我认为这归结为我不理解“@id”。它说它来自angularjs 站点的“数据对象” ,我不确定这意味着什么。
任何帮助将不胜感激。
更新
另一个问题。我还没有找到任何使用 angularjs 使用嵌套资源(示例 User has_many :missions, through: :user_missions
)和$resource
. 有没有一个 angularjs$resource
使用 ajax 操作嵌套资源(with )的好例子?