我正在对我自己的 heroku rails 移动 iOS 照片共享应用程序版本进行最后润色。我已经在 iOS 上通过 HTTP 实现并成功发送了 POST 和 GET 请求。不幸的是,Heroku 教程明确声明不会讨论如何编写 DELETE 请求。这是我到目前为止所拥有的:
+ (void)deletePhoto:(NSString *)owner
image:(NSString *)recordId
block:(void (^)(Photo *, NSError *))block
{
NSMutableDictionary *mutableParameters = [NSMutableDictionary dictionary];
[mutableParameters setObject:recordId forKey:@"photo[id]"];
NSLog(@"Destroying %@", recordId);
[[CloudGlyphAPIClient sharedClient] deletePath:@"/photo" parameters:mutableParameters success:^(AFHTTPRequestOperation *operation, id JSON) {
if (block) {
NSLog(@"DELETE sussessful");
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
if (block) {
block(nil, error);
}
}];
}
+ (void)getPhotos:(NSString *)owner
block:(void (^)(NSSet *photos, NSError *error))block
{
NSMutableDictionary *mutableParameters = [NSMutableDictionary dictionary];
[mutableParameters setObject:owner forKey:@"photo[owner]"];
[[CloudGlyphAPIClient sharedClient] getPath:@"/photos" parameters:mutableParameters success:^(AFHTTPRequestOperation *operation, id JSON) {
NSMutableSet *mutablePhotos = [NSMutableSet set];
for (NSDictionary *attributes in [JSON valueForKeyPath:@"photos"]) {
Photo *photo = [[Photo alloc] initWithAttributes:attributes];
[mutablePhotos addObject:photo];
}
if (block) {
block([NSSet setWithSet:mutablePhotos], nil);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
if (block) {
block(nil, error);
}
}];
}
我基于 GET 请求的 DELETE 请求,但在这种情况下,我们正在寻找特定所有者的特定图像用户。我收到一个错误,即路由文件不包含 DELETE /photos 的路径...我将 destroy 方法添加到 rails 应用程序并获取 routes.rb 文件。
我觉得这是某个地方的rails GOTCHA ..感谢您的帮助^_^
TL;DR尝试使用 AFNetworking 为 Rails 应用程序编写 DELETE 请求