Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't use variable for basic operations in Nanoc
    primarykey
    data
    text
    <p>I got a quite annoying problem tonight, and maybe someone here will be able to help me.</p> <p>I'm building a static blog with nanoc, and currently making some helpers for next/previous articles (I included some tests I made and the return):</p> <pre class="lang-ruby prettyprint-override"><code># lib/helpers.rb include Nanoc3::Helpers::Blogging include Nanoc3::Helpers::LinkTo # Returns a link to the next article # If the article in param is the most recent, returns nothing def next_article article articles = sorted_articles # returns an array of article ordered by date pos = articles.index(article) # returns the expected integer pos.class # returns Fixnum pos.nil? # returns false pos + 1 # NoMethodError: undefined method `+' for nil:NilClass return if pos.zero? # NoMethodError: undefined method `zero?' for nil:NilClass link_to(articles[pos+1][:title], articles[pos+1]) # Fails too, obviously end </code></pre> <p>I have absolutely no idea of why I can't use the "pos" variable, but can still perform some read on it. If anyone has an insight, I'll take it. Thanks in advance !</p> <p>(I use ruby-1.9.3p194, with rvm, on OSX Lion, if it may have any relation)</p> <p>Update : I should have precised that the returned value for pos is the expected value when just read. Strangely enough, setting </p> <pre><code>pos = articles.index(article).to_s.to_i </code></pre> <p>seems to work though. I just don't understand how &amp; why it happens.</p> <pre><code>#layout/post_navigation.haml .post_navigation .next =next_article @item </code></pre>
    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.
 

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