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 6368739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:42:50+00:00 2026-05-25T00:42:50+00:00

I have a helper method ‘default_content_for’ which can be used to provide default content

  • 0

I have a helper method ‘default_content_for’ which can be used to provide default content for yield sections. However when I’m using it, I get weird output from the helper.

I’m pretty sure I’m probably missing something simple, but still not sure what is wrong.

The title ends up full of stuff above the beginning of the block. Like so:

<title>   Default Title&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt;      &lt;title&gt;   Default Title   </title>

application.html.erb

<!DOCTYPE html>
<html>
<head>

  <title>
  <% default_content_for :title do %>
    Default Title
  <% end %>
  </title>

  <%= stylesheet_link_tag :all %>
  <%= javascript_include_tag :defaults %>
  <%= csrf_meta_tag %>
</head>
<body>


<%= yield %>

</body>
</html>

<!DOCTYPE html>
<html>
<head>

  <title>
  <% default_content_for :title do %>
    Default Title
  <% end %>
  </title>

  <%= stylesheet_link_tag :all %>
  <%= javascript_include_tag :defaults %>
  <%= csrf_meta_tag %>
</head>
<body>


<%= yield %>

</body>
</html>

helper method

module ApplicationHelper
    def default_content_for(name, &block)
      name = name.kind_of?(Symbol) ? ":#{name}" : name
      out = eval("yield #{name}", block.binding)
      out = (out ? (out.empty? ? false : out): false) || capture(&block)
      concat(out)
    end
end

output

<!DOCTYPE html>
<html><head>

  <title>   Default Title&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt;      &lt;title&gt;   Survey Builder   </title>


  <script type="text/javascript" src="/javascripts/prototype.js?1314309079"></script>
<script type="text/javascript" src="/javascripts/effects.js?1314309079"></script>
<script type="text/javascript" src="/javascripts/dragdrop.js?1314309078"></script>
<script type="text/javascript" src="/javascripts/controls.js?1314309078"></script>
<script type="text/javascript" src="/javascripts/rails.js?1314309079"></script>
<script type="text/javascript" src="/javascripts/application.js?1314309078"></script>
  <meta content="authenticity_token" name="csrf-param">
<meta content="oG4mVUt5wy6aWdhbxmXa3tYh3DUgXVUQy9d6uxng6a0=" name="csrf-token">
</head>
<body>

<div id="user_nav">
        Logged in as KARL KIRCH
        <a href="/log_out">Log out</a>
</div>


<h1>Home#index</h1>
<p>Find me in app/views/home/index.html.erb</p>




</body></html>
  • 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-05-25T00:42:51+00:00Added an answer on May 25, 2026 at 12:42 am

    Okay so I should read things.
    In rails 3 blocks are supposed to use the following form:

    <%= default_content_for :title do %>
    <% end %>
    

    Also helper methods are supposed to only return a string not a concat, so I changed my helper method like so (with suggestion from agmcleod

      module ApplicationHelper
        def default_content_for(name, &block)
          name = name.kind_of?(Symbol) ? ":#{name}" : name
          out = eval("yield #{name}", block.binding)
          if out && !out.empty?
            out
          else
            capture(&block)
          end
        end
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have helper method which is only checking if User is Authenticated but its
I have a helper method which encrypts some data on the iPhone. If the
I have created a helper method for generating a li content tag with a
I have a helper method that serialises an object, which works until you try
I have this helper method that I can't seem to clean up with content_tag
I have a helper method which checks whether the collection of objects is empty?
I have an object obj that is passed into a helper method. public static
I have an MVC view with a form built with the Ajax.BeginForm() helper method,
I have a helper function, which basically calls CompareTo on two objects, but does
I have a helper assembly which includes a function to identify object types: namespace

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.