2012-10-25 43 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。