1

I have a working Ruby on rails app. I would like to add a native iOS app that can get data from eh server and display it. Anybody knows of a good end to end toturial to create a native ios app that works against a ruby on rails app?

4

1 回答 1

1

Unless I'm missing something in your question, what you can do is set up all your actions to render json. So what ends up happening is that your iOS app makes a call to the Rails server and the Rails server returns json to the iOS app, where you can then do whatever you want with the data.

Example

def some_action
  @users = User.all

  render :json => @users.to_json
end

Performance of Rendering JSON

More on rendering data fast into json.

Authenticating an User

For Non-Devise Apps

One method I've done, and I'm sure there are better, is to send your credentials via a post request to the Rails server. If the user has the correct username and password, then I'll return the user a token that is unique for each user. Then every time the user is doing something with the database and it's important, you send the token from the iOS app as part of the post request to Rails and it validates it for persistent user authentication.

For Devise Apps

TokenAuthenticatable is one solution for Devise. You send the token to the iOS app, store it, then when the user is doing something important to the database, you send the token back from the iOS app to Rails. Rails validates the token, then do whatever you want.

于 2013-04-14T16:50:53.243 回答