[英]Rails equivalent of respond_to |format| with a straight render
我经常使用ActiveResource,因此我的服务模型仅使用XML。 因此,我不需要render :xml => @model
块,我实际上只是render :xml => @model
但是,我无法弄清楚如何使用此来呈现404标头。 我不得不诉诸response_to,我认为这增加了一些不必要的方法调用。 这是我正在使用的:
respond_to do |format|
if (record_found)
render :xml => @some_record
else
format.xml{ head :not_found }
end
end
但是我只想要像render :xml => head :not_found
这样的东西,它不起作用。 谁能告诉我正确的语法?
你有没有尝试过:
render {:xml => "Record not found", :status => :not_found }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.