Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to POST from Restkit + iOS to Rails

My Rails app has a Post model with a "name" property. I'm trying to create a new Post from iOS using RestKit. Here's the iOS code.

NSDictionary* params = [NSDictionary dictionaryWithObject:@"amazingname" forKey:@"name"];
[[RKClient sharedClient] post:@"/posts" params:params delegate:self];

And here's the server log running on the same machine

    Started POST "/posts" for 127.0.0.1 at Tue May 10 15:39:14 -0700 2011
  Processing by PostsController#create as JSON
  Parameters: {"name"=>"amazingname"}
MONGODB blog_development['posts'].insert([{"_id"=>BSON::ObjectId('4dc9be92be2eec614a000002')}])
Completed 406 Not Acceptable in 4ms

As you can see, the server gets the request, but the name doesn't get saved into the DB. a nameless Post gets created. What is wrong with my iOS code?

like image 576
John Avatar asked May 10 '11 22:05

John


2 Answers

It works when I switch forKey:@"name" to forKey:@"post[name]"

like image 110
John Avatar answered Sep 24 '22 01:09

John


Or you could do

NSDictionary* attributes = [NSDictionary dictionaryWithObject:@"amazingname" forKey:@"name"];
NSMutableDictionary *params = 
[NSMutableDictionary dictionaryWithObject:attributes forKey:@"post"];
like image 28
Arnaud Avatar answered Sep 23 '22 01:09

Arnaud