开发者

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: {"na开发者_JS百科me"=>"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?


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


Or you could do

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜