I’m pretty new to ruby, I keep getting the following error:
in gem_original_require': ./helpers/navigation.rb:28: odd number list for Hash (SyntaxError)
Any help appreciated…
module Sinatra::Navigation
def navigation
@navigation
nav = {
primary[0] = {
:title => "cheddar",
:active => false,
:children => {
{ :title => "cheese", :active => false },
{ :title => "ham", :active => false }
}
},
primary[1] = {
:title => "gorgonzola",
:active => false,
:children => {
{ :title => "What is the cheese?", :active => false },
{ :title => "What cheese", :active => false },
{ :title => "What does the cheese tell us?", :active => false, :children => {
{ :title => "Cheessus", :active => false },
{ :title => "The impact of different cheeses / characteristics for cheese in relation to CHSE outcomes", :active => false }
}
}
}
}
}
In ruby curly braces are used to describe a hashmap consisting of pairs of keys and values. Square brackets are used to describe arrays. Your children attribute does not contain key-value-pairs, so you have to make into an array instead of a hash.
So instead of
do:
And the same for the other occurrence of
:children.I’m also not sure what
primary[0] =is supposed to achieve, but it almost certainly doesn’t do what you want it to. What it does do is assign is set the first element ofprimary(which means that an array called primary has to exist before that assignment) and then return that element.If you want to structure your hash so that it can be accessed like
nav[:primary][0][:children][0], you have to do it like this:Also note that the line
@navigationright before you assign tonavdoes nothing at all.