【发布时间】:2012-02-13 04:07:44
【问题描述】:
我在这里专注于错误的抽象层,但不知道在哪里。
我有这个文件views/pages/overview.html.erb
<%= stylesheet_link_tag "cust/coderay"%>
<h1>Overview</h1>
<hr>
Here's my code test:
<%= html = CodeRay.scan("puts 'Hello, world!'", :ruby).div(:line_numbers => :table)%>
<hr>
Back <%=link_to "home", "home"%>.
<hr>
It took <%="%.3f" %(Time.now-@start_time)%> seconds to generate this page.
令我惊讶的是,页面呈现如下:
当我在页面上查看源代码时:
<!DOCTYPE html>
<html>
<head>
<title>Dash</title>
<link href="/assets/application-all.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/all/pages.css?body=1" media="all" rel="stylesheet" type="text/css" />
<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/pages.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>
<meta content="authenticity_token" name="csrf-param" />
<meta content="SydEiDhSNHuEE6vCfr4rajIksxBbqnm89sddC08msjs=" name="csrf-token" />
</head>
<body>
<h1>Overview</h1>
<hr>
Here's my code test:
<table class="CodeRay"><tr>
<td class="line-numbers" title="double click to toggle" ondblclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }"><pre>
</pre></td>
<td class="code"><pre>puts <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Hello, world!</span><span style="color:#710">'</span></span></pre></td>
</tr></table>
<hr>
Back <a href="home">home</a>.
<hr>
It took 0.006 seconds to generate this page.
</body>
</html>
为什么括号内的 CSS 显示为内联文本?我对 coderay 的使用在这里应该是什么样子?
非常感谢 -
【问题讨论】:
-
+1 同意。我的问题并没有增加太多,除了关键字'coderay'可能会让像我这样的其他可怜的灵魂得到答案。我永远不会找到您指出的类似线程,因为我只是不知道“转义的 HTML”是问题所在。
标签: ruby ruby-on-rails-3 view gem