【发布时间】:2015-05-18 22:25:54
【问题描述】:
我想在多部分请求后从我的 API 返回一个 json 响应。
请求成功并按预期保存了所有内容,但之后我似乎无法呈现 json - 它只是呈现 html。
这是我的代码:
def create
@article = Article.new(article_params)
respond_to do |format|
if @article.save
format.multipart_form { render :show, status: :created, location: @article }
format.html { redirect_to @article, notice: 'Article was successfully created.' }
format.json { render :show, status: :created, location: @article }
else
format.multipart_form { render json: @article.errors, status: :unprocessable_entity }
format.html { render :new }
format.json { render json: @article.errors, status: :unprocessable_entity }
end
end
end
我从 iOS 应用程序发送请求,这里是请求标头:
{
"Content-Length" = 563285;
"Content-Type" = "multipart/form-data; boundary=2EA4A96C-18A6-4E1E-9140-DAC63D1066E7";
}
我是否需要在我的请求中指定其他内容,或者我在我的 rails create 方法中做错了什么?
【问题讨论】:
标签: ruby-on-rails json multipartform-data multipart