2
我希望我的Rails rest应用程序具有json作为默认输出格式,我也想删除html格式。有什么建议么?谢谢RoR响应输出类型
我希望我的Rails rest应用程序具有json作为默认输出格式,我也想删除html格式。有什么建议么?谢谢RoR响应输出类型
是的,你可以做到这一点。
在你的控制器,
respond_to do |format|
#format.html # show.html.erb
#format.xml { render :xml => @post }
format.json { render :json => @post }
end
,或者你可以把它处理JavaScript的
respond_to do |format| format.js { render :json { :only => :name}.to_json end
then you just access your action with ".js" in the end
尝试像JSON这样
format.any(:xml, :html, :json) { render :json => @post }
如何让默认呈现而不使用respond_to代码块? – Fivell 2011-03-11 12:42:18
更新后的帖子。 – Ashish 2011-03-11 12:58:16