Ruby-on-rails 解释“”是什么意思

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24602154/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 23:45:54  来源:igfitidea点击:

Explain what &quot means

ruby-on-rails

提问by user3711600

I can't find a clear explanation of what it means when a value/variable is surrounded by '&quot' and why it happens.

当一个值/变量被 '"' 包围时,我无法清楚地解释它的含义以及它发生的原因。

For example, I have a simple function which returns an array containing an id.

例如,我有一个简单的函数,它返回一个包含 id 的数组。

return [params[:id]]

For some reason, it returns:

由于某种原因,它返回:

["4"]

not:

不是:

[4]

which I would have expected.

这是我所期望的。

Can someone explain what '&quot' is and why/how they are inserted?

有人可以解释什么是“"”以及为什么/如何插入它们?

回答by Richard Peck

Unicode

统一码

I believe it's something called unicode- a standardized way of outputting typography & character sets in digital media. Unicode takes many forms, ASCII being one of the most widely used.

我相信这是一种叫做unicode的东西——一种在数字媒体中输出排版和字符集的标准化方式。Unicode 有多种形式,ASCII 是使用最广泛的一种。

The problem you have, as referred to in the comments, is that as you returned the pure param, you're getting back the string representation of its contents. Whilst the actual contents of the variable will be ["4"], HTML will treat it as [&quot4&quot]

正如评论中所提到的,您遇到的问题是,当您返回纯参数时,您将返回其内容的字符串表示形式。虽然变量的实际内容是["4"],但 HTML 会将其视为[&quot4&quot]

If you want to output the returned data, you may want to try the [.raw()][2]method in your view:

如果你想输出返回的数据,你可能想.raw()][2]在你的视图中尝试 [方法:

<%= raw( [data] ) %>

回答by Barbbara

&quot4&quotwould mean "4".

&quot4&quot将意味着"4"