我在我的控制器中遇到了一个奇怪的行为。他们似乎偶尔想要重定向而不是呈现 json 响应。
respond_to :json, :html, :js
def create
@favorite = current_user.favorites.build(:location_id=>params[:location_id])
if @favorite.save
respond_with(@favorite)
else
respond_with(@favorite.errors)
end
end
Run Code Online (Sandbox Code Playgroud)
我认为它大部分时间都有效,但今天我收到了这个错误的通知:
NoMethodError: #<FavoritesController:0x00000006171dc0> 的未定义方法 `favorite_url'
params 哈希记录为:
{"format"=>"json",
"action"=>"create",
"user_id"=>"56",
"auth_token"=>"iGSty8CMIaWsbShYZEtw",
"location_id"=>"47943",
"controller"=>"favorites"}
Run Code Online (Sandbox Code Playgroud)
特别奇怪,因为它似乎大部分时间都在工作......我已经改变了我的一些其他控制器来使用旧的 format.json { render :json => @object } 语法,但如果可能的话我想避免这种情况.
这怎么可能?
我无法弄清楚为什么我在最后一行收到此错误:'SKNode!' 不是'SKNode'的子类型
func move_background(){
let enumerationBlock: (SKNode, CMutablePointer<ObjCBool>) -> Void = { bg, stop in
var bg_velocity = CGPointMake(0,CGFloat(-self.bg_velocity))
var distance_to_move = self.point_multiply_scalar(bg_velocity, b: self.dt!)
bg.position = self.point_add(bg.position, b: distance_to_move)
if bg.position.y <= -bg.frame.height {
bg.position = CGPointMake(bg.position.x, bg.position.y + bg.frame.height * 2)
}
}
self.enumerateChildNodesWithName("bg", usingBlock: enumerationBlock)
}
Run Code Online (Sandbox Code Playgroud)
你们有人可以帮助我吗?
我有以下代码将 RAW 图像以 JPEG 格式保存到相机胶卷中,但它存在三个问题:1)它是镜像,2)它旋转了 90 度,3)它的分辨率较低。
// In my PhotoCaptureDelegate
func capture(_ captureOutput: AVCapturePhotoOutput, didFinishProcessingRawPhotoSampleBuffer rawSampleBuffer: CMSampleBuffer?, previewPhotoSampleBuffer: CMSampleBuffer?, resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Error?) {
if ( rawSampleBuffer != nil) {
let temporaryDNGFileURL = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("\(resolvedSettings.uniqueID)lld.dng")!
let temporaryJPGFileURL = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("\(resolvedSettings.uniqueID)lld.jpg")!
let imageData = AVCapturePhotoOutput.dngPhotoDataRepresentation(forRawSampleBuffer: rawSampleBuffer!, previewPhotoSampleBuffer: previewPhotoSampleBuffer)
try! imageData?.write(to: temporaryDNGFileURL)
PHPhotoLibrary.requestAuthorization({ (status) in
if status == .authorized {
PHPhotoLibrary.shared().performChanges({
let options = PHAssetResourceCreationOptions()
options.shouldMoveFile = true
//Write Raw:
PHAssetCreationRequest.forAsset().addResource(with: .photo, fileURL: temporaryDNGFileURL, options: options)
// Process Raw …Run Code Online (Sandbox Code Playgroud)