15

I've just spent a lot of time looking into the best ways to create iphone and android apps for an existing rails app that I've built and I feel that I haven't actually gotten any closer to knowing how to best achieve this.

What I want:

  • I would like to have the rails app and the mobile code cleanly separated. I'm not looking to just render a different layout in my rails app. I'd prefer to use something like phone gap that allows me to use roughly the same codebase to run the mobile apps.
  • I'd like to have offline/sync capabilities in the mobile apps (hence if a user creates a record on their iphone while they are out of coverage the app should save the record on the phone and continue to try to to sync that record to the web app until success.
  • Having access to the hardware features will be needed down the road. GPS, accelerometer, etc.

My questions:

  • Is this a good situation to use oauth? Would I just build an oauth provider into my web app and then build the two mobile apps as clients to the web app?
  • Is there an easier method for secure authorization that I'm missing?
  • Does Devise work with oauth? My app is built on top of devise at the moment.
  • Is this syncing something that should be abstracted to a middleware or metal?

Sorry, I know this is actually a lot of questions but I'd like someone who is familiar with the situation to answer in a comprehensive manner rather than just a couple little pokes that leave more questions. I feel like this has to be a common situation now-a-days but I can't seem to find anything up-to-date in my searches.

Cheers!

ps. - If you've done something like this yourself and know how to pull it off, I'd love to talk to you directly. I'll even buy the beers. Seriously... no takers?

erskingardner
  • 2,198
  • 1
  • 20
  • 24
  • Erskingardner, when you have multiple questions, you're supposed to create multiple questions so that each one can have a seperate set of answers, searchable and useful for other people as well. – edgerunner Nov 23 '10 at 08:44

3 Answers3

4

I am building a mobile application with a grails backend, must support android and iphone

I have done a few iterations so far while attempting to settle on technology, a native objective-c, native android, phoneGap and titanium appcelerator.

for authentication I use HTTPS with basic auth. I know people are concerned about basic-authentication, but it has been argued both ways see this StackOverflow Question

I have not solved the syncing problem yet, but I dont expect to implement that complex of a solution initially, will store local content (XML or JSON) and push back to server on demand. Content is stored locally in same format used when posting to server

Backend in grails, all REST API calls are logged and authenticated on each request. Will probably add additional security only allowing specific registered devices to access the API as and additional level of security

Community
  • 1
  • 1
Aaron Saunders
  • 33,180
  • 5
  • 60
  • 80
3

I've been building a iPhone app with a Rails back end. I've been using Objective-C because it needs the full Core Location framework which isn't available with a browser based solution. So if you want to use the full capabilities of the device, you have to use the native development environment.

I've been using Objective Resource http://iphoneonrails.com/ which is an open source framework that provides Active Resource-like extensions to Objective C NSObject classes and plays very well with my Rails App. You just have to put in render JSON or XML for your controller actions like in the example below.

 class UsersController < ApplicationController
 # GET /users
 # GET /users.xml
 def index
   @users = User.all

  respond_to do |format|
  format.html # index.html.erb
  format.xml  { render :xml => @users }
  format.json  { render :json => @users }
end

end

I don't if this answers all your questions as I don't know enough about your app but it's a good starting point.

Robert Redmond
  • 1,522
  • 13
  • 16
  • Cool. Thanks for the quick response Robert. With that solution, is your rails backend accessible by a normal web interface as well? Or is it just serving to the iphone app? I'd be really interested in hearing more about Objective Resource, but I'll look into it before I start asking questions. – erskingardner Oct 21 '10 at 15:55
  • It's accessible by a web interface as well but that just for testing purposes as it is designed purely as iPhone app backend. I develop the Rails code, test it initially on the browser then use Objective Resource to hook up with it. – Robert Redmond Oct 21 '10 at 16:05
  • What, if any, authentication are you using between the app and the backend - any gotchas/tips on that? Thanks. – Chris Kimpton Dec 17 '10 at 09:40
  • My app is at a prototype stage so I haven't done anything about authentication yet. – Robert Redmond Dec 20 '10 at 10:33
0

Maybe you will find useful my example rails + ember.js App with token authentication based on ember-auth and several OAuth strategies. It is responsive and works both as a desktop and mobile App with Phonegap.

Currently in de the devel branch: https://github.com/joscas/base_app/tree/devel

Life here: https://starter-app-staging.herokuapp.com for the desktop version.

It uses the phonegap-rails gem (of which I'm also the author) to export the apps assets, fix paths etc without hassle.

joscas
  • 7,474
  • 5
  • 39
  • 59
  • Hey @joscas could you please provide some more details on this? I am trying to create something similar, an application which works on Android when offline and sync with rails server hosted on vps. When the application is able to access internet it will connect to the rails server and upload/fetch the data. – rahoolm Dec 28 '14 at 20:26
  • For the offline data sync of that application I would use Couchbase mobile http://developer.couchbase.com/mobile/. See they have Phonegap support. Otherwise a basic CouchDB replication would work if you don't have multiple users and security issues. – joscas Dec 28 '14 at 21:09