Phonegap and Rails 3: How to Interact with a Rails 3 App

Phonegap App communicate with Rails 3 App using authentication

The answer was two fold.

First I had to add this to my ajax requests in the iOS app:

xhrFields: {
withCredentials: true
}

as in...

$.ajax({
url: ....,
type: "GET",
xhrFields: {
withCredentials: true
},
complete: hideLoader,
error: function(xhr,txt,err) {
// you can't get back anyways
window.location.hash = "";
},
success: function(data,status,res) {
window.location.hash = "";
}
});

Second I had to add this to my Application Controller in the Rails app:

def protect_against_forgery?
unless request.format.json?
super
end
end

Using Phonegap as a native container for a Rails 3 App

I do not believe such a container exists to run on the client side but it is possible to dynamically serve a PhoneGap app (i.e. the app acts as a web browser with native functionality available via javascript commands).

Here is code which demonstrate exactly what you are describing.

Here is a screen cast I did associated with demo.

NOTE: The demo is using an out 3.2.1, and is broken as of the latest version Xcode and/or PhoneGap but it is possible, and apps of this nature are valid in the the various app stores, (Linkedin alongwith many others are already doing it.) The logic is there I just haven't had the time to fix the bug with the new version of Xcode, or update the PhoneGap code (doing the update may actually fix the bug in one quick work session).



Related Topics



Leave a reply



Submit