Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When stretch attributes to multiline in Haml, I got an unbalanced brackets error

Tags:

haml

The following code gives me unbalanced bracket error at line 4

%ul
  - @sentences.each do |sentence|
    %li
      %a{id:"s-#{sentence.id}",
      href:"/sentence/#{sentence.id}",
      'data-type' => 'text',
      'data-url' => "/sentence/#{sentence.id}",
      'data-toggle' => 'manual'
      }= sentence.content
      %a{href:'#'}
        %i.icon-pencil



Haml::SyntaxError at /user/1/sentence
Unbalanced brackets.
file: sentences.haml location: nil line: 4

any idea?

like image 950
mko Avatar asked Nov 28 '12 02:11

mko


3 Answers

I found the problem myself, the closing } should not in a new line like any other languages

'data-toggle' => 'manual'}
  = sentence.content

will work

like image 193
mko Avatar answered Oct 07 '22 19:10

mko


I found other solution it may work for the others. According to the docs it is required to use | on multiline content. Of course closing bracket can't be in the new line. Example:

  %a{id:"s-#{sentence.id}", |
  href:"/sentence/#{sentence.id}", |
  'data-type' => 'text', |
  'data-url' => "/sentence/#{sentence.id}", |
  'data-toggle' => 'manual'}= sentence.content
like image 33
jmarceli Avatar answered Oct 07 '22 18:10

jmarceli


This one worked for me. Try adding a comma after your last key-value pair.

For instance

... 'data-url' => "/sentence/#{sentence.id}", 'data-toggle' => 'manual', }

Note the , after 'manual'. This worked for me. Hope it helps someone.

like image 34
Kaka Ruto Avatar answered Oct 07 '22 18:10

Kaka Ruto