[英]Missing template on render
我的錯誤:
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'
編輯:
出現的實際錯誤是“圖像不能為空白”。
衛生署。 我的參數錯誤。 只是需要請某人查看一下。
檢查您的驗證,這是阻止您保存模型的原因,它進入了else
語句。
錯誤消息應告訴您問題所在。
您可能還會遇到以下問題:
render status: 500
這是造成混亂和MissingTemplate
錯誤的原因,您缺少了template參數
render :template => "public/500.html", :status => 500
編輯quantumpotato
原來的問題是從Obj-C代碼發送的image
是使用image
查詢參數而不是photo
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.