My Rails应用程序有一个带有"name"属性的Post模型。我正在尝试使用 RestKit 从 iOS 创建一个新帖子。这是iOS代码。
NSDictionary* params = [NSDictionary dictionaryWithObject:@"amazingname" forKey:@"name"];
[[RKClient sharedClient] post:@"/posts" params:params delegate:self];
这是在同一台计算机上运行的服务器日志
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
如您所见,服务器收到请求,但名称不会保存到数据库中。 将创建一个无名称的帖子。我的 iOS 代码有什么问题?
当我将 key:@"name" 切换到 forKey:@"post[name]" 时它有效
或者你可以做
NSDictionary* attributes = [NSDictionary dictionaryWithObject:@"amazingname" forKey:@"name"];
NSMutableDictionary *params =
[NSMutableDictionary dictionaryWithObject:attributes forKey:@"post"];