I have a very simple Rails action as shown below:
def create
@story = Story.new(story_params)
if(@story.save)
render :json => {:success => 'true', :message => 'Story saved successfully!'}
else
render :json => {:success => 'true', :message => 'Error creating story'}
end
end
I invoke the above method from my iPhone app using AFNetworking:
[self POST:@"stories/create" parameters:@{@"story[title]":story.title,@"story[abstract]":story.abstract} success:^(NSURLSessionDataTask *task, id responseObject) {
if(success) success(task,responseObject);
} failure:^(NSURLSessionDataTask *task, NSError *error) {
if(failure) failure(task,error);
}];
I get the following message:
"The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x8ca3500 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}
I used Charles to see the network traffic and I get the following:
story[abstract] Asd
story[title] asdas
What does it mean and how can I get to work?
UPDATE:
I tried the other approach mentioned below but still the same issues:
[self POST:@"stories/create" parameters:@{@"story": @{
@"title": story.title,
@"abstract": story.abstract
}
}
success:^(NSURLSessionDataTask *task, id responseObject) {
NSLog(@"Success");
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(@"%@",error.description);
NSLog(@"FAILED");
}];