Rails 5.1 removes a whole load of previously deprecated methods。其中有老朋友render :text
。
当您需要呈现某些文本时,它非常有用,但不需要视图模板的开销。例子:
render text: "ok"
render text: t('business_rules.project_access_denied'), status: 401
反而使用什么?
答案 0 :(得分:94)
不推荐使用的方法是使用render :plain
Rails Guide on Layouts and Rendering:
2.2.6渲染文本
您可以使用
:plain
选项将纯文本(完全没有标记)发送回浏览器:render plain: "OK"
而不是render nothing: true
(也已删除),现在应该使用head :ok
。同样的事情:发送http 200响应代码,只发送标题,没有内容。