I have taken the Rails 3 Tutorial app by Michael Hartl and have expanded on it in several areas. However, I kept the login and session handling the same. I would like to interface with an iphone app, but am not sure how. I've looked at RestKit and Objective Resource, but thought I would roll my own. I've been testing it out with cURL, but have had no luck so far. I've been using this command
curl -H 'Content-Type: application/json' -H 'Accept: application/json' -X POST http://www.example.com/signin -d "{'session' : { 'email' : 'email@gmail.com', 'password' : 'pwd'}}" -c cookie
As in the Rails 3 tutorial, I'm using Sessions.
These are the routes:
match '/signin', :to => 'sessions#new'
match '/signout', :to => 'sessions#destroy'
This is the controller:
class SessionsController < ApplicationController
def new
@title = "Sign in"
end
def create
user = User.authenticate(params[:session][:email],
params[:session][:password])
if user.nil?
flash.now[:error] = "Invalid email/password combination."
@title = "Sign in"
render 'new'
else
sign_in user
redirect_back_or user
end
end
def destroy
sign_out
redirect_to root_path
end
end
There is no model and you sign in with a form. Here is the html for the form:
<h1>Sign In</h1>
<%= form_for(:session, :url => sessions_path) do |f| %>
<div class="field">
<%= f.label :email %></br>
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :password %></br>
<%= f.password_field :password %>
</div>
<div class="actions">
<%= f.submit "Sign in" %>
</div>
<% end %>
<p> New user? <%= link_to "Sign up now!", signup_path %></p>
Sorry if this is too much information, I wanted to give as much as possible.
Basically, I would like to be able to access my Rails database from a native iphone app. If someone has good advice on how to sign in, store a session, and then make other calls to the website, I would greatly appreciate it.
However, if this isn't possible, a working cURL request would probably get me going in the right direction. Thanks!