大佬教程收集整理的这篇文章主要介绍了ruby-on-rails – 在Rails 3中返回空的JSON响应的首选方法是什么?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想发送一个空的JSON响应与200代码,像
head :no_content
要么
render :nothing => true,:status => 204
(How to return HTTP 204 in a Rails controller的例子).
通常我一直这样做:
render :json => {}
要么
render :json => 'ok'
有没有更喜欢或更多的Rails-y方式呢?
respond_to do |format| if @product.update_attributes(params[:product]) format.html { redirect_to(@product,:notice => 'Product was @R_874_6048@sfully updated.') } format.xml { head :ok } format.json { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @product.errors,:status => :unprocessable_entity } format.json { render :json => @product.errors,:status => :unprocessable_entity } end end
完美的工作,这是最重要的.
以上是大佬教程为你收集整理的ruby-on-rails – 在Rails 3中返回空的JSON响应的首选方法是什么?全部内容,希望文章能够帮你解决ruby-on-rails – 在Rails 3中返回空的JSON响应的首选方法是什么?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。