Rails 5.1 removes a whole load of previously deprecated methods。其中包括老 friend render :text
。
当您需要渲染一些文本,但又不想增加 View 模板的开销时,它非常有用。例子:
render text: "ok"
render text: t('business_rules.project_access_denied'), status: 401
用什么代替呢?
最佳答案
不推荐使用的方法是使用render :plain
Rails Guide on Layouts and Rendering:
奖金
现在应该代替render nothing: true
(也已删除),而不是head :ok
。做同样的事情:发送http 200响应代码,仅发送 header ,不发送任何内容。