ruby-on-rails – 在rails 5.1及更高版本中使用什么而不是`render:text`(以及`render nothing:true`)?

Rails 5.1 removes a whole load of previously deprecated methods.其中有老朋友渲染:文字.

当您需要渲染一些文本但不想要视图模板的开销时,它非常有用.例子:

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:

06000

奖金

而不是渲染任何东西:真实(也被删除),现在应该使用head:ok.做同样的事情:发送http 200响应代码,只发送标题,没有内容.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...