9

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?

mko
  • 21,334
  • 49
  • 130
  • 191

3 Answers3

11

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

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

will work

mko
  • 21,334
  • 49
  • 130
  • 191
  • seems the important thing is indentation http://stackoverflow.com/questions/13930603/haml-syntax-split-a-line-to-a-couple-of-rows – sites May 11 '13 at 15:53
  • 5
    not only the last `}` need to have preceding characters but the first `{` also require some following characters as well – herophuong Dec 31 '13 at 02:37
4

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
jmarceli
  • 19,102
  • 6
  • 69
  • 67
  • Old answer, I know, but this is inaccurate. You can leave out the pipes in this example because each line ends in a comma. – henrebotha Nov 03 '15 at 08:42
2

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.

Kaka Ruto
  • 4,581
  • 1
  • 31
  • 39