title: Create User in Devise from JSON
body: <p>I'm working on integrating my Rails 3.1 app running Devise for user authentication with my iOS app.  I'd like the user to be able to register from the application, and then I can store those credentials to login later.</p>
  
  <p>Using RestKit, I do this:</p>
  
  <pre><code>-(IBAction)registerUser:(id)sender {
      NSDictionary *params = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:
                                                                  self.email.text,
                                                                  self.password.text,
                                                                  self.confirmPassword.text,
                                                                  nil]
                                                         forKeys:[NSArray arrayWithObjects:
                                                                  @"email",
                                                                  @"password",
                                                                  @"password_confirmation",
                                                                  nil]];
  
      [[RKClient sharedClient] post:@"/users.json" params:params delegate:self];
  }
  </code></pre>
  
  <p>The <code>/users.json</code> url goes to: <code>user_registration POST   /users(.:format)                         {:action=&gt;"create", :controller=&gt;"devise/registrations"}</code> (according to rake routes).  It appears that the post call accepts different formats, so I assume it will accept JSON.  My Post request is serialized as JSON, and sent off.  The server gets it, and this is the log:</p>
  
  <pre><code>Started POST "/users.json" for 129.21.84.10 at 2012-01-12 15:33:57 -0500
    Processing by Devise::RegistrationsController#create as JSON
    Parameters: {"password"=&gt;"[FILTERED]", "password_confirmation"=&gt;"[FILTERED]", "email"=&gt;"test1@test.com"}
  WARNING: Can't verify CSRF token authenticity
    User Load (0.9ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
     (0.3ms)  BEGIN
     (0.2ms)  COMMIT
     (0.2ms)  BEGIN
     (0.4ms)  ROLLBACK
  Completed 422 Unprocessable Entity in 93ms (Views: 3.8ms | ActiveRecord: 10.2ms)
  </code></pre>
  
  <p>I get a 422 error, and my user is not created.  The response my iOS app gets is: <code>Response: {"email":["can't be blank"],"password":["can't be blank"]}</code>.  But the password and email isn't blank, the server got them successfully.  So, something isn't working right, and I'm not sure where to go.  How can I create the user using JSON?</p>
  
  <p>Thanks for helping!</p>