I currently have a rails application using Devise and I can log in to my browser. Now I want to create my own iPhone application that uses this rails application as a backend. What I would like:
- When a user first opens the iOS application, they are presented with a login screen.
- They put them in the information, and the application tries to register them. If successful, it lists the users of the rails application (for now). Otherwise, it indicates an incorrect login.
- The user can then click on usernames and display user profiles, etc. The application should be able to perform all CRUD operations as if they were on the site itself.
I am currently using Devise and RestKit for an iPhone application. I have enabled http_auth in my rails application and I can set the username / password and return a response from my / users page (list of my users in JSON).
Rails:
class UsersController < ApplicationController before_filter :authenticate_user! def index @users = User.all respond_to do |format| format.html
iPhone (using Restkit):
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. RKClient *client = [RKClient clientWithBaseURL:@"http://192.168.1.105:3000" username:@"xxxx" password:@"xxxx"]; [[RKClient sharedClient] get:@"/users.json" delegate:self]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)request:(RKRequest*)request didFailLoadWithError:(NSError *)error { NSLog(@"error"); } - (void)request:(RKRequest*)request didLoadResponse:(RKResponse*)response { NSLog(response.bodyAsString); }
I am not sure what to do next or how to approach it.
- How do I handle the login screen? Ok, I can do an 'http: // localhost: 3000' GET using http basic auth and get the users list back, but this is how I should check if the user credentials were entered correctly? Is there a way to get an OK or NOT OK response to login?
- What is the best way to interact with the rails app? Is it possible to do things like GET / users / 2 using RestKit? Or do I need to build some kind of api? I donβt know where to start with something like this.
source share