iOSデバイスがJSONパラメーターをRailsサーバーに送信し、コンテンツをコンソールに出力します。paramsハッシュに奇妙な文字が含まれていることがわかります。サーバーメソッドは、これらのパラメーターを使用してオブジェクトを作成できません。そして、データベースには何も保存されません。これを修正するにはどうすればよいですか?ありがとう
iOSデバイスからJSONを送信するコード:
//Create a Dictionary of Parameters which will be convertedto JSON object
NSMutableDictionary *mutableParameters = [NSMutableDictionary dictionary];
[mutableParameters setObject:_entryID forKey:@"id"];
[mutableParameters setObject:fnameExt forKey:@"image_file_name"];
[mutableParameters setObject:_lat forKey:@"lat"];
[mutableParameters setObject:_longitude forKey:@"lng"];
[mutableParameters setObject:_description forKey:@"description"];
NSMutableDictionary *photoDict = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObject:mutableParameters]
forKeys:[NSArray arrayWithObject:@"photo"]];
//Create a Request Object
NSMutableURLRequest *mutableURLRequest = [[appAPIClient sharedClient]
multipartFormRequestWithMethod:@"POST"
path:@"/photos"
parameters:photoDict
constructingBodyWithBlock:^(id<AFMultipartFormData> formData)
{ .....}
私のRailsサーバー
# POST /photos
# POST /photos.json
def create
@photo = Photo.new(params[:photo])
puts "Photo ="
puts "Server received Photo with attributes= #{@photo.inspect}"
@photo.save
end
サーバーでのコンソール出力
15:11:19 web.1 | Photo =
15:11:20 web.1 | Server received Photo with attributes= #<Photo id: nil, lat: nil,
lng: nil, created_at: nil, updated_at: nil, image_file_name: "someFile.jpg",
image_content_type: "image/jpeg", image_file_size: 0, image_updated_at: "2013-02-
18 23:11:17">
15:11:20 web.1 | Started POST "/photos" for 127.0.0.1 at 2013-02-18 15:11:17 -0800
15:11:20 web.1 | Processing by PhotosController#create as JSON
15:11:20 web.1 | Parameters: {"photo%5BentryID%5D"=>"1",
"photo%5Blng%5D"=>"-122.406417", "photo%5Blat%5D"=>"37.785834",
"photo%5Bimage_file_name%5D"=>"someFile.jpg",
"photo%5Bdescription%5D"=>"Description", "photo"=>{"image"=>#
<ActionDispatch::Http::UploadedFile:0x007fa314c07768
@original_filename="someFile.jpg", @content_type="image/jpeg", @headers="Content-
Disposition: form-data; name=\"photo[image]\";
filename=\"someFile.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#
<File:/var/folders/dh/1k2rdp_51yd2k43xzkc2pmdh0000gn/T/RackMultipart20130218-2872-
13gqqo5>>}}