2012-10-25 42 views
0

我正在对我自己版本的heroku rails移动iOS照片共享应用程序进行收尾。我已经在iOS上通过HTTP实现并成功发送了POST和GET请求。不幸的是,Heroku教程明确指出它已经胜利,不会去写如何编写DELETE请求。这是我到目前为止有:使用Rails AFNetworking和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 /照片的路径...我添加了销毁方法的rails应用程序和raked routes.rb文件。

我觉得这是一个轨道GOTCHA地方..感谢您的帮助^ _^

TL; DR试图写,删除请求一个Rails应用程序与AFNetworking

+0

它看起来像deletePath应该是尝试删除资源的网址 - 不知道如何形成?此外,Rails应用程序使用回形针,但我认为在销毁方法,我只需要说'@ photo'.image.destroy。照片是ActiveRecord,图像是附件字段。 –

回答

0

在AFNetworking中, DELETE路径是这样一个url路径:photos/18.json是标记为删除的记录。在这里找到答案: Answer

实际上,可以将字符串连接到表中的ActiveREcord的url。