Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 从Rails ERB模板将HTML呈现为字符串,不包含unicode字符_Ruby On Rails_Ruby_Json_Unicode_Encoding - Fatal编程技术网

Ruby on rails 从Rails ERB模板将HTML呈现为字符串,不包含unicode字符

Ruby on rails 从Rails ERB模板将HTML呈现为字符串,不包含unicode字符,ruby-on-rails,ruby,json,unicode,encoding,Ruby On Rails,Ruby,Json,Unicode,Encoding,下面的代码段运行时没有错误,但是,它在响应中返回unicode字符: if params[:template] == 'Application Acknowledgement' render json: { :template => render_to_string(:template => "template.erb") } end ERB发回包含动态内容的HTML模板,但下面的HTML如下所示: 模板中的HTML: <!doctype html> <htm

下面的代码段运行时没有错误,但是,它在响应中返回unicode字符:

if params[:template] == 'Application Acknowledgement'
  render json: { :template => render_to_string(:template => "template.erb") }
end
ERB发回包含动态内容的HTML模板,但下面的HTML如下所示:

模板中的HTML:

<!doctype html>
<html>
  <head>
  </head>
</html>
如何在Rails中以字符串形式从控制器返回正常的UTF-8HTML


添加

问题在于将unicode字符串转换为json,例如:

"абв".to_json
变成

"\"\\u0410\\u0411\\u0412\""
鉴于
JSON::dump('АБb')
返回
“\”АБb\\”
,传递给
呈现JSON:
的每一个unicode字符都将转义


如何避免在呈现json时转义unicode符号?

为什么要将其呈现为json?因为除了HTML之外,还有其他数据呈现回客户端。我只是没有将其包含在问题中,因为它与问题无关。它与呈现模板一起工作,但我需要将模板之外的额外数据发送回客户端。看来问题在于。还有一个很好的答案
"\"\\u0410\\u0411\\u0412\""