Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.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 轨道';render正在生成奇怪的、微妙错误的内容_Ruby On Rails_Internet Explorer_Actionview - Fatal编程技术网

Ruby on rails 轨道';render正在生成奇怪的、微妙错误的内容

Ruby on rails 轨道';render正在生成奇怪的、微妙错误的内容,ruby-on-rails,internet-explorer,actionview,Ruby On Rails,Internet Explorer,Actionview,我有一个应用程序,可以为人们托管简单的html页面。有些人使用表格进行设计布局。(我发誓不是我!)出于某种神秘的原因,渲染会破坏Internet Explorer中的这些布局 这是我能够重现这个问题的最简单方法 当我将html文件保存到public/中并通过Mongrel访问它时,它在所有浏览器中都显示良好。如果我使用以下代码渲染文件,它会变得很时髦: render :file => '[app_directory]/public/sample.html' Internet Explor

我有一个应用程序,可以为人们托管简单的html页面。有些人使用表格进行设计布局。(我发誓不是我!)出于某种神秘的原因,渲染会破坏Internet Explorer中的这些布局

这是我能够重现这个问题的最简单方法

当我将html文件保存到public/中并通过Mongrel访问它时,它在所有浏览器中都显示良好。如果我使用以下代码渲染文件,它会变得很时髦:

render :file => '[app_directory]/public/sample.html'
Internet Explorer为每个换行符创建一个空文本节点,这会导致表中出现空白。原始html显然是相同的,但当与render一起使用时,它会以某种方式发生变化,使Internet Explorer不高兴

如果有人给我指点如何阻止这一切,我将不胜感激。谢谢

编辑1:神秘加深了。。。 我已经想出了如何让Chrome出现同样的错误。以下是在Chrome中工作的代码,在IE中被破坏:

# tab_controller.rb
render :inline => tab.public_html
但当我将其更改为使用外部ERB模板时,Chrome中也会出现奇怪的空白:

# tab_controller.rb
@html = tab.public_html
render 'show'

# show.erb
<%=raw @html %>
下面是IE为通过render生成的内容提供的响应头。存在以下问题的内容:

Response         HTTP/1.1 200 OK
Connection       close
Date             Fri, 05 Aug 2011 00:28:18 GMT
Content-Type     Text/html
X-UA-Compatible  IE=Edge
ETag             "43d392ddbbcf3856ced3de672005c26f"
Cache-Control    max-age=0, private, must-revalidate
Set-Cookie       _rails_static_html_session=[session stuff]; path=/; HttpOnly
X-Runtime        31.964569
Transfer-Encoding   chunked
编辑3:代码 您可以(我希望)通过将以下代码放入任意随机控制器来重现问题:

html = "<html>\n<head>\n</head>\n\n<body>\n<table width='520' height='870' border='0' cellpadding='0' cellspacing='0'>\n  <tr>\n    <td align='center' valign='top'><div align='center'>\n      <table width='520' border='0' cellspacing='0' cellpadding='0'>\n        <tr>\n          <td><img src='.' width='520' height='314' /></td>\n        </tr>\n        <tr>\n          <td><img src='.' width='520' height='320' /></td>\n        </tr>\n        <tr>\n          <td><img src='.' width='520' height='166' /></td>\n        </tr>\n        <tr>\n          </tr>\n      </table>\n    </div></td>\n  </tr>\n</table>\n</body>\n</html>"

render :inline => html
File.open('/railsappdirectory/public/sample_html.html', 'w') {|f| f.write(html) }
html=“\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n”
render:inline=>html
open('/railsappdirectory/public/sample_html.html','w'){f | f.write(html)}

当您使用Internet Explorer通过rails应用程序访问此文件时,图像之间会有间隙。当您将html文件视为静态资产时,将不会有任何间隙。

我使用了一个简单的php文件来提供具有不同标题的相同内容,并发现以下标题栏是导致问题的原因:

X-UA-Compatible: IE=Edge
上的一条评论解释了如何阻止rails提供此标头。在config/environments/*.rb文件中,确保以下设置为false:

config.action_dispatch.best_standards_support = false

谢谢大家的帮助

您是否在公共视图中使用资源管理器,以及在使用
渲染时使用资源管理器?IE呈现内容的方式与其他浏览器不同。是。哈哈,我敏锐地(痛苦地)意识到IE呈现内容的方式与其他浏览器不同。我喜欢你这样说这可能与内容标题有关。如果使用render_to_string获取原始文本会发生什么情况?James,我认为您关于标题的看法可能是正确的。我只是试着把字符串渲染成字符串,它看起来是绝对正常的标记。我将编辑该问题,以添加与该问题一起出现的标题信息和不包含该问题的标题信息。您应该将解决方案添加为答案并接受它,以便将此问题标记为已回答。有趣的问题,谢谢发布解决方案。
config.action_dispatch.best_standards_support = false