我的错误:
ActionView::MissingTemplate (Missing template api/magic_photos/create, api/base/create, application/create with {:locale=>[:en], :formats=>[:html, :text, :js, :css, :ics, :csv, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip], :handlers=>[:erb, :builder, :coffee, :rabl]}. Searched in:
2014-08-15T16:15:45.610918+00:00 app[web.1]:
2014-08-15T16:15:45.610928+00:00 app[web.1]: * "/app/app/views"
2014-08-15T16:15:45.610929+00:00 app[web.1]: * "/app/vendor/bundle/ruby/1.9.1/gems/devise-2.1.2/app/views"
控制器代码:
if photo.save
magic_photo = photo.magic_photos.build( magic: magic )
magic_photo.save
render json: photo.json_hash(magic, current_user)
else
render status: 500
end
的CURL
curl -X POST -F" photo = @ / path / path.jpg; type = image / jpg" " http://magic-photo-app.herokuapp.com/api/magics/44/photosdescription=SomeDescription123&auth_token=DQWCqasiqVqYZxNp3W1y"
工作并返回JSON。
当我提出此请求时,我得到500并且缺少模板错误
description = [description stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *path = [NSString stringWithFormat:@"api/magics/%@/photos?description=%@&auth_token=%@", magic.identifier, description, [NSUserDefaults authToken]];
NSString *fullPath = [NSString stringWithFormat:@"%@%@", [CURequestHelpers baseURL], path];
NSData *imageData = UIImageJPEGRepresentation(image, 0.25f);
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[CURequestHelpers baseURL]];
NSURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:path parameters:@{} constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
NSString *fileName = @"image.jpg";
[formData appendPartWithFileData:imageData name:@"image" fileName:fileName mimeType:@"image/jpg"];
}];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
[self.delegate pictureUploadProxyUploadDidSucceed:self];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"UPLOAD ERROR RESPONSE: %@", operation.responseString);
NSLog(@"UPLOAD ERROR: %@", error);
[self.delegate pictureUploadProxyUploadDidFail:self];
}];
NSOperationQueue *q = [[NSOperationQueue alloc] init]; [q addOperation:operation];
为什么我的CURL会在Obj-c中的HTTP POST失败的地方成功?
途径:
namespace :api do
resources :magics, only: [:index, :show, :create, :album] do
resources :photos, only: [:index, :show, :create], controller: 'magic_photos'
编辑:
显示的实际错误是&#34;图片不能为空白&#34;。
卫生署。我的参数错了。只需要让别人看一下......
答案 0 :(得分:1)
检查您的验证,有些内容阻止您的模型被保存,并且会进入您的else
声明。
错误消息应该告诉您问题所在。
您可能还遇到以下问题:
render status: 500
这是造成混淆和MissingTemplate
错误的原因,你错过了模板参数
render :template => "public/500.html", :status => 500
EDIT quantumpotato
原来问题是Obj-C代码发送的图像是使用image
查询参数而不是photo
发送的。