Created
October 13, 2010 07:17
-
-
Save dalibor/623617 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var currentMedia = false; | |
// Get photo | |
Ti.Media.showCamera({ | |
mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO], | |
success: function(event) { | |
var cropRect = event.cropRect; | |
currentMedia = event.media; | |
}, | |
error:function(error) { | |
Ti.UI.createAlertDialog({title:'Camera problem', message:'Camera problem or device has no camera.'}).show(); | |
}, | |
allowImageEditing:true, | |
saveToPhotoGallery:false | |
}); | |
// Send photo | |
var xhr = Titanium.Network.createHTTPClient(); | |
xhr.onerror = xhrOnError; | |
xhr.onload = function() { | |
var json = JSON.parse(this.responseText); | |
if (json.status === "ok") { | |
showSuccess(); | |
} else { | |
showError(json); | |
} | |
}; | |
var data = {"_method": "PUT", "photo": currentMedia}; | |
xhr.open('PUT', apiEndpoint + options.problem_id); | |
xhr.send(data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rails backend | |
def update | |
@problem = Problem.find(params[:id]) | |
@problem.photo = params[:photo] | |
@problem.save | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment