0

我刚刚从 3.0.7 升级到 3.2.8 并且没有显示一堆部分。但是,它们正在被渲染(根据日志),并且没有给出错误消息。这是一个(简化的)示例:

布局/application.html.haml

(snip)
%body
  = yield :header
  = yield
(snip)

主页/index.html.haml

- content_for :head do
  (snip)

- content_for :header do
  (snip)

= render(:partial => "home_content", :layout => "shared/layouts/content_columns")

共享/布局/_content_columns.html.haml

%div
  .content
    = yield :content_column
  .sidebar
    = yield :sidebar

主页/_home_content.html.haml

- content_for :content_column do
  = render_external("twitter")
  = render(:partial => "seo_content")

- content_for :sidebar do
  = render(:partial => "featured")
  = render(:partial => "testimonials")
  = render(:partial => "social")

:head显示and的所有内容:header,而没有:content_columnor:sidebar内容。我认为使用布局渲染局部会发生一些变化,但是一些快速搜索并没有产生任何明显的结果。

谢谢!

更新

这是日志中的渲染顺序(包括我在 中包含的调试语句shared/layouts/_content_columns.html.haml):

Rendered home/_twitter.html.haml (1.4ms)
Rendered home/_seo_content.html.haml (0.9ms)
Rendered home/_featured.html.haml (2.2ms)
Rendered home/_testimonials.html.haml (2.1ms)
Rendered home/_social.html.haml (213.8ms)
DEBUG: String="Rendering shared/layouts/content_columns"
DEBUG: String="At '= yield :content_column'"
DEBUG: String="At '= yield :sidebar'"
Rendered home/_home_content.html.haml (256.9ms)
Rendered home/index.html.haml within layouts/application (300.6ms)

如您所见,部分内容是在 and 之前渲染的home_contentindex因此它们的内容应该由= yieldin抓取layouts/application

4

1 回答 1

1

答案是改变shared/layouts/_content_columns.html.haml

%div
  .content
    = content_for :content_column
  .sidebar
    = content_for :sidebar

感谢这个 SO 问题:content_for vs yield in partials

于 2012-09-14T21:02:53.390 回答