自分のバージョンのherokurailsモバイル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のパスが含まれていないというエラーが表示されます...railsアプリにdestroyメソッドを追加し、routes.rbファイルをレーキしました。
これはどこかでレールGOTCHAのように感じます..あなたの助けに感謝します^_^
TL;DRがAFNetworkingを使用してRailsアプリのDELETEリクエストを書き込もうとしています