Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 3 - yield return or callback won't call in view <%= yield(:sidebar) || render('shared/sidebar') %>
    text
    copied!<p>I'm migrating a Website from Rails 2 (latest) to Rails 3 (beta2).<br> Testing with <em><strong>Ruby 1.9.1p378</strong></em> and <em><strong>Ruby 1.9.2dev</strong> (2010-04-05 trunk 27225)</em></p> <p>Stuck in a situation, i don't know which part will work well. Suspect <code>yield</code> is the problem, but don't know exactly.</p> <p>In my Layout Files I use the following technique quite often:</p> <p><em><code>app/views/layouts/application.html.erb</code></em>:</p> <pre><code>&lt;%= yield(:sidebar) || render('shared/sidebar') %&gt; </code></pre> <hr> <p>For Example the partial look like:</p> <p><em><code>app/views/shared/_sidebar.html.erb</code></em>:</p> <pre><code>&lt;p&gt;Default sidebar Content. Bla Bla&lt;/p&gt; </code></pre> <hr> <p>Now it is time for the key part!<br> In any view, I want to create a <code>content_for</code> block (optional). This can contain a pice of HTML etc. example below. If this block is set, the pice HTML inside should render in <code>application.html.erb</code>.<br> If not, Rails should render the Partial at <code>shared/_sidebar.html.erb</code> on the right hand side.</p> <p><em><code>app/views/books/index.html.erb</code></em>:</p> <pre><code>&lt;% content_for :sidebar do %&gt; &lt;strong&gt;You have to read REWORK, a book from 37signals!&lt;/strong&gt; &lt;% end %&gt; </code></pre> <hr> <p>So you've got the idea. Hopefully. This technique worked well in any Rails 2.x Application.<br> Now, in <strong>Rails 3</strong> <em>(beta2)</em> only the <code>yield</code> Part is working.</p> <pre><code>|| render('shared/sidebar') </code></pre> <p>The <code>or</code> side will not process by rails or maybe ruby.</p> <p>Thanks for input and time!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload