【问题标题】:superfluous output of yield_contentyield_content 的多余输出
【发布时间】:2012-09-27 00:41:15
【问题描述】:

当我使用yield_content 时,我在页面中看到奇怪的输出。请看下文。 注意[#<Proc:0x850a14c@/home/akonsu/project/index.erb:1>] 部分。这是什么?

布局.erb:

<!DOCTYPE html>
<html>
  <head>
    <%= yield_content :head %>
  </head>
  <body>
    <%= yield %>
  </body>
</html>
索引.erb:
<% content_for :head do %>
  <script type="text/javascript" src="/js/jquery.js"></script>
<% end %>
<div id="contents">
...
</div>
输出:
<!DOCTYPE html>
<html>
  <head>
  <script type="text/javascript" src="/js/jquery.js"></script>
[#<Proc:0x850a14c@/home/akonsu/project/index.erb:1>]
  </head>
  <body>

...
正文>

标签: ruby sinatra erb


【解决方案1】:

这是因为&lt;%=。在 ruby​​ 1.9 中,它应该使用 &lt;% 代替。

<% yield_content :head %>

【讨论】:

    猜你喜欢
    • 2021-12-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-01
    • 1970-01-01
    • 2022-11-26
    • 1970-01-01
    • 2021-01-04
    • 1970-01-01
    相关资源
    最近更新 更多