Rails 相当于 respond_to |format|直接渲染
我经常使用 ActiveResource,因此我的服务模型仅使用 XML。因此,我不需要 respond_to 块,我实际上只是 render :xml =>; @model
但是我无法弄清楚如何使用它来渲染 404 标头。我不得不求助于respond_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
不起作用。谁能告诉我正确的语法?
I'm working with ActiveResource a lot so my service models are only using XML. Thus, I have no need for a respond_to block, I literally just render :xml => @model
I can't however figure out how to render a 404 header using this. I've had to resort to respond_to, which I think adds a few unnecessary method calls. Here's what I'm using:
respond_to do |format|
if (record_found)
render :xml => @some_record
else
format.xml{ head :not_found }
end
end
but I just want something like render :xml => head :not_found
which doesn't work. Can anyone tell me the proper syntax?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你有没有尝试过:
Have you tried: