Why does this little code snippet (for a navigational helper with css classes) give me an undefined method 'include?' for nil:NilClass
on the elseif
-line?
The page_classes_string
may be something like 'oddchap oddchap_zoidberg oddchap_zoidberg_index'. I think the purpose of this method is clear:
- Get rid of the last word in the
page_classes_string
if it contains '_index' - Compare the
page_classes_string
to the currentpage_string
and return a string with an appropriate class name for some navigation.
I tried this code in irb and of course it works, but not within my middleman config. I also could rewrite it by using a third variable that gets assigned my `page_classes_string', but that seems kind of cumbersome. Any suggestions?
Of course the _string
attached to the following variable names is for clarification purposes only.
def nav_active(page_string)
if page_classes_string.match(/_index/)
page_classes_string = page_classes_string.split(/ /)[0..-2].join(' ')
end
if page_classes_string == page_string
'active'
elsif page_classes_string.include? page_string
'semiactive'
else
nil
end
end