Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on rails server app + IOS iphone client?

What is the best way to have a regular ruby on rails app be delivered true an IOS iphone app?

The Idea is to build, for fun and education schoolproject, an simple Iphone app that connects to the ruby on rails app for its data. Seen some articles outdated, would like to ask some advise on this server - client model for ruby and an ios app.

  • How to move data from ruby app to IOS app xml ?
  • How to interact from IOS app back with the Ruby on Rails Application?
  • Are there opensource example apps or recent updated resources you would recommend on this topic ( gems, opensource projects, tutorials, documentations )

Also what would be good websites to checkout when doing ruby on rails and Iphone apps? Would love to hear some feedback, I already investigated and have rough idea on above concepts but as said on older resources. Some first hand experience from you experts would be higly appreciated thx!

like image 399
Rubytastic Avatar asked Feb 06 '12 08:02

Rubytastic


1 Answers

The general setup for a Rails backend like this could be:

Authentication: use a basic authentication sceme to authenticate to the rails backend. I would use Devise and CanCan for this, they are easy to set up and work great. If you do not want people to log in but want authentication nonetheless, you could use a token.

Push Notifications : use the APN Gem

GET data: use the GET controllers of your Rails backend, you can either specifically ask for json or just return json as default /articles/:id.json

def show
  begin
    @article = Article.find(params[:id])
  rescue Exception => e
    render :text => "unknown article id", :status => 404
  else
    render json: @article
  end
end

If you would want a custom JSON returned. You can override it in the model:

#overide default json output
def as_json(options)
  # this ignores the user's options
  super(:only => [:id , :type, :title, :content])
end

CREATE data: use the Create controller of you Rails backend, you can just submit like you would a form, so a POST with fields like article[:title]=value. If you like you could return a plain text or json if the create was succesfull.

UPDATE data: use the Update controller of your rails backend. You use a PUT here instead of a POST.

like image 176
Benjamin Udink ten Cate Avatar answered Sep 30 '22 11:09

Benjamin Udink ten Cate