views:

64

answers:

1

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.

+2  A: 

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
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
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