John
John

Reputation: 5905

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?

Upvotes: 5

Views: 2720

Answers (2)

Arnaud
Arnaud

Reputation: 17737

Or you could do

NSDictionary* attributes = [NSDictionary dictionaryWithObject:@"amazingname" forKey:@"name"];
NSMutableDictionary *params = 
[NSMutableDictionary dictionaryWithObject:attributes forKey:@"post"];

Upvotes: 1

John
John

Reputation: 5905

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

Upvotes: 6

Related Questions