Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7874907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:53:34+00:00 2026-06-03T02:53:34+00:00

In rails 3.0 with HAML (3.1.4) I have some template-like partial , like _template.html.haml:

  • 0

In rails 3.0 with HAML (3.1.4) I have

  1. some template-like partial, like _template.html.haml:

    .panel.top
      = yield :panel_top
    
    .content
      = yield
    
  2. some another partial which will be displayed using prev template (all this stuff is rendered using AJAX, but this doesn’t matter)

    - content_for :panel_top do
     .title.left
       = title
    
    content text
    

and this worked like a charm in Rails 3.0

But, after upgrade to 3.2 this fails! Yiels just yields “content text”, so I have “content text” twice and no title at all

only changing = yield :panel_top to = content_for :panel_top works for 3.2

I am not sure that this solution is ok, and if it is stable or recommended, I cannot find any notes about changes in yield processing nor in Rails 3.1 release notes, nor in 3.2 ones.

Can you help what is the best way to organize yielding inside partials?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:53:34+00:00Added an answer on June 3, 2026 at 2:53 am

    From Rails 3.0 to Rails 3.2 content_for was really changed:

    3.0:

    def content_for(name, content = nil, &block)
        content = capture(&block) if block_given?
        @_content_for[name] << content if content
        @_content_for[name] unless content
    end
    

    3.2:

    def content_for(name, content = nil, &block)
      if content || block_given?
        content = capture(&block) if block_given?
        @view_flow.append(name, content) if content
        nil
      else
        @view_flow.get(name)
      end
    end
    

    This shows us, that from 3.2 content_for works for showing/inserting content too, not only store it for named section.

    Also, if you make an attempt to debug yield logic you’ll se that it yields before content_for is correctly initialized.

    So, leaving fragment caching out of this discussion I can conclude that content_for is preferrable way to insert named sections anywhere except top-level layouts. In helpers and other situations yield should render wrong results.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Ruby on Rails application that is using HAML based template views.
I am using haml with my rails application and i have a question how
[Rails] Where to put this code? I have a user1 and when another registered
I added some Haml templates to my Rails 3 project with git clone git://github.com/psynix/rails3_haml_scaffold_generator.git
I've got some experience using haml (+sass) on rails projects. I recently started using
I have some javascript I would like to execute only if a user is
I use rails and haml, haml-rails. How I create hidden_field in haml? I have
I'm using the gems haml and haml-rails in my rails app and I have
my question concerns about Rails + HAML I would like to conditionally set a
I have a rails create action which send back some jquery in a file:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.