I have been trying to create a three level hash to dump into a template, but the deepest layer of the hash seems to not work.
My hash:
$clusters = {
'Default' => {
'hostname' => '127.0.0.1',
'port' => '11211'
},
},
}
My ERB template (modified for readability):
<% @clusters.sort.map do |k,v| -%>
<% if v.is_a?(Hash) -%>
'<%= k %>'
<% @clusters[k].sort.map do |ki, vi| -%>
<% if vi.is_a?(Hash) -%>
'<%= ki %>'
<% @clusters[ki].sort.map do |kii, vii| -%>
<% if vi and vi != '' -%>
'<%= kii %>' = '<%= vii %>',
<% end -%>
<% end -%>
<% end -%>
<% end -%>
<% end -%>
<% end -%>
For some reason that I can't quite figure out, the innermost hash throws a Detail: undefined method `sort' for nil:NilClass error. I assume if ki was not a hash, the if vi.us_a?(Hash) would have been false and skipped that sort.
What am I doing wrong here?