我目前正在开发一个通过XML和JSON与Ruby on Rails应用程序连接的Android应用程序.
我现在可以通过XML从我的网站上提取所有帖子,但我似乎无法通过JSON发布.
我的应用程序当前从一个看起来像这样的形式的表单构建一个JSON对象:
{
"post": {
"other_param": "1",
"post_content": "Blah blah blah"
}
}
Run Code Online (Sandbox Code Playgroud)
在我的服务器上,我相信我的帖子控制器中的Create方法设置正确:def create @post = current_user.posts.build(params [:post])
respond_to do |format|
if @post.save
format.html { redirect_to @post, notice: 'Post was successfully created.' }
format.json { render json: @post, status: :created, location: @post }
format.xml { render xml: @post, status: :created, location: @post }
else
format.html { render action: "new" }
format.json { render json: @post.errors, status: :unprocessable_entity }
format.xml { render xml: @post.errors, status: :unprocessable_entity } …Run Code Online (Sandbox Code Playgroud)