Search code examples
ruby-on-railsruby-on-rails-3ruby-on-rails-3.1ruby-on-rails-3.2

Just upgraded from 3.0.7 to 3.2.8; Partials not displaying


I just upgraded from 3.0.7 to 3.2.8 and a bunch of partials are not being displayed. However, they are being rendered (according to the logs), and no error message is given. Here's a (simplified) example:

layouts/application.html.haml

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

home/index.html.haml

- content_for :head do
  (snip)

- content_for :header do
  (snip)

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

shared/layouts/_content_columns.html.haml

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

home/_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")

All the content for :head and :header is displayed, while none of the :content_column or :sidebar content is. I figure something changed with rendering partials with layouts, but some quick searching didn't yield anything obvious.

Thanks!

UPDATE

Here's the rendering order from the logs (including debug statements I included in 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)

As you can see, the partials are being rendered before home_content and index, so their content should be grabbed by the = yield in layouts/application


Solution

  • The answer is to change shared/layouts/_content_columns.html.haml:

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

    Thanks to this SO question: content_for vs yield in partials