error at blank record in data set: "no implicit conversion of nil into String (TypeError)"
mtlx03 opened this issue · 1 comments
mtlx03 commented
Hi, your plugin is a lifesaver. I'm new to Jekyll and Ruby so please pardon my ignorance.
I'm getting this error, and failed output:
(eval):1:in `+': no implicit conversion of nil into String (TypeError)
when the script encounters a blank record (deliberate) in the csv data file:
biz | zip
ABC | 99835
XYZ | 99840
FGH | 99623
VBN |
ASD | 99833
config.yml looks like:
page_gen:
- data: 'my-data'
template: 'default'
name_expr: record['biz'] + "_" + record['zip']
title: 'biz'
dir: 'misc'
debug: yes
I'd like the filename to be biz
and (optionally, only if it exists) _zip
.
Here's more of the debug output:
debug (datapage-gen) Record read:
>> {"biz"=>"VBN", "zip"=>nil}
debug (datapage-gen) Configuration variables:
>> index_files: false
>> dir: misc
>> page_data_prefix:
>> name:
>> name_expr: record['biz'] + "_" + record['zip']
>> title: zip
>> title_expr:
>> template: default
>> extension: html
(eval):1:in `+': no implicit conversion of nil into String (TypeError)
Many thanks for having a look!
avillafiorita commented
Hi,
the issue is with the zip
field, which is empty in the record before the last one: this causes name_expr
to fail, since record['zip']
returns nil
and nil
cannot be concatenated to a string.
Try changing name_expr
with something like:
name_expr: "#{record['biz']}_#{record['zip']}"
or
name_expr: (record['biz'] || "") + "_" + (record['zip'] || "")
Let me know if it works!