Rails 3.1.4 - 渲染:文本 [英] Rails 3.1.4 - Render :text
本文介绍了Rails 3.1.4 - 渲染:文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将我的 rails 2 应用程序更新到 rails 3 并发现使用 'render :text' 的行为不再相同.
I'm updating my rails 2 apps to rails 3 and find that the use of 'render :text' does not behave the same anymore.
@results 是一个数组.在我的控制器中:
@results is an array. In my controller:
render :text => "<ul>#{@results}</ul>"
它将整个数组作为字符串返回,而不是遍历每个值:
It's returning the whole array as a string rather than iterating through each value:
<ul>
["
<li>Steve</li>
", "
<li>John</li>
"]
</ul>
在 Rails 2.x 中工作正常,但在 3.x 中不行.我该如何解决这个问题?
Worked fine in Rails 2.x but not in 3. How do I fix this?
我期待以下结果:
<ul>
<li>Steve</li>
<li>John</li>
</ul>
推荐答案
我知道这个问题仅适用于 Rails 3.1.4.
I know this question is for Rails 3.1.4 only.
但是那些来到这里并且使用更新版本的人,从 Rails 5.1 开始,我们将这样做:
But those who come here and are on a more recent version, starting with Rails 5.1 we'll do this:
render plain: "I'm like everyone else."
这篇关于Rails 3.1.4 - 渲染:文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文