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.
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!
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With