Note that there are some explanatory texts on larger screens.

plurals
  1. POPass entire array as local variable into partial, then render another partial with collection
    text
    copied!<p>I have a layered partial scheme and am trying to write DRY code. I need to pass a variable into a partial and maintain its array status so that within the partial I can render another partial with the <code>:collection</code> parameter.</p> <p><strong>on this page I render the <code>'feed'</code> partial:</strong></p> <pre><code> %div.row %div.span6 %h1 Posts /Post feed =render 'feed',:locals =&gt; {:feed_items =&gt; @posts} %div.span6 %h1 Groups /Group feed =render 'feed', :locals =&gt; {:feed_items =&gt; @groups} </code></pre> <p><strong>Here is the <code>'feed'</code> partial:</strong></p> <pre><code>%ol -if feed_items.first.is_a?(Post) =render :partial =&gt; 'post_feed_item', :collection =&gt; feed_items -else =render :partial =&gt; 'group_feed_item', :collection =&gt; feed_items =will_paginate feed_items </code></pre> <p><strong>Currently gives me this error:</strong></p> <pre><code>undefined local variable or method `feed_items' for #&lt;#&lt;Class:0x007fa8e2aa8b00&gt;:0x007fa8e5405390&gt; </code></pre> <p><strong>UPDATE 1:</strong></p> <p>real error. final partial doesn't recognize component of the <code>:collection</code> passed to it:</p> <pre><code>undefined local variable or method `feed_item' for #&lt;#&lt;Class:0x007fa8e2aa8b00&gt;:0x007fa8e2c6d670&gt; </code></pre> <p><strong>final partial <code>'post_feed_item'</code>(layer 3?):</strong></p> <pre><code>%li.feed_item.row-fluid %div.image.span3 =link_to image_tag(feed_item.assets.empty? ? '/assets/small.png': feed_item.assets.first.image.url(:small), :alt =&gt; feed_item.title), post_url(feed_item) </code></pre> <p>So there is some problem in the first partial...<code>feed_items</code> isn't being parsed as an array?</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