我正在对我自己版本的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文件。
我觉得这是某个地方的铁路GOTCHA ..感谢您的帮助^ _ ^
TL; DR 尝试使用AFNetworking为rails应用写入DELETE请求
答案 0 :(得分:0)
在AFNetworking中,DELETE路径是这样的url路径:photos / 18.json是标记为要删除的记录。在这里找到答案: Answer
实际上,可以将字符串连接到表中ActiveREcord的url。