Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The issue is that a <code>product</code> is <code>nil</code>:</p> <blockquote> <blockquote> <p>undefined method 'page_url' for nil:NilClass". Solution:</p> </blockquote> </blockquote> <p>(It has <em>nothing</em> to do with <code>page_url</code> <em>maybe</em> returning <code>nil</code>.)</p> <p>Make sure <code>product</code> can't be <code>nil</code>: but be wary that this may be a deeper issue. In any case, "fixing" this issue is easy to deal with.</p> <p>Consider either using a collection restriction (such as <a href="http://www.ruby-doc.org/core/classes/Enumerable.html#M001489" rel="nofollow">Enumerable#reject</a>):</p> <pre><code>@all_products.reject(&amp;:nil?).each do { ... } </code></pre> <p>The above uses the <a href="http://www.sitepoint.com/insta-block-with-symbolto_proc/" rel="nofollow">Symbol#to_proc "Rails magic"</a>, but could just as easily have been <code>{|x| x.nil?}</code> as the restriction. The downside is it's not practical to use this for a "no URL" condition per-product although <a href="http://www.ruby-doc.org/core/classes/Enumerable.html#M001496" rel="nofollow">Enumerable#partition</a> could help with that: use the right tool for the job.</p> <p>Another solution is to expand the conditional check itself:</p> <pre><code>if product &amp;&amp; product.page_url("en_US") # yay else # uhm end </code></pre> <p>The short-circuit nature of <code>&amp;&amp;</code> will ensure <code>page_url</code> is only invoked upon a truthy value (which excludes <code>nil</code>).</p> <p>I also took the liberty of assuming <code>page_url</code> can't return <code>false</code> as I find this makes the intent more clear.</p> <p>Happy coding.</p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    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