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 :
2.2.6 Rendering Text
You can send plain text - with no markup at all - back to the browser by using the
:plain
option to render:render plain: "OK"
奖金
现在应该使用 head :ok
,而不是 render nothing: true
(也已删除)。做同样的事情:发送 http 200 响应代码,只有 header ,没有内容。
关于ruby-on-rails - 在 Rails 5.1 及更高版本中使用什么代替 `render :text` (和 `render nothing: true` )?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43428991/