Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're doing way too much in your view. Really you should figure out all of this in the controller and pass through a cleaned up structure that you can iterate over for display purposes.</p> <p>As an example:</p> <pre><code>length = [ @items_p.length, @items_m.length ].sort.last @messages = [ ] length.times do |i| item_p = @items_p[i] item_m = @items_m[i] if (item_p and (item_m and item_p.paymt &lt; item_m.maint) or !item_m) @messages &lt;&lt; "#{item_p.name} payment required in ..." elsif (item_m and (item_p and item_m.maint &lt; item_p.paymt) or !item_p) @messages &lt;&lt; "#{item_m.name} maintenance required in ..." end end </code></pre> <p>You would then iterate over <code>@messages</code> as required.</p> <p>The real problem here is that you haven't structured these objects for this sort of thing strategically speaking. It would be nice if you had a single method for the due date instead of having to differentiate between <code>paymt</code> and <code>maint</code> according to the type. Likewise, it would be better if both of these were paired up into an Array instead of supplied separately.</p> <p>If you had them in <code>[ p, m ]</code> pairs you could iterate much more simply:</p> <pre><code>items.each do |pair| first_due = pair.compact.sort_by(&amp;:due).first @messages &lt;&lt; "#{first_due.name} #{first_due.action} required in ..." end </code></pre> <p>The <code>action</code> method would return <code>payment</code> or <code>maintenance</code> as required.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

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