Reputation: 8588
I just switched to HAML and converting my erb to haml. I am experiencing an error (unexpected keyword else) when setting up the code as I think it should look:
= if signed_in?
%li= link_to "Users", '#'
%li#fat-menu.dropdown
%a.dropdown-toggle{ href: '#', data: { toggle: "dropdown" } }
Account
%b.caret
%ul.dropdown-menu
%li= link_to "Profile", current_user
%li= link_to "Settings", '#'
%li.divider
%li= link_to "Log out", signout_path, method: "delete"
= else
%li= link_to "Log in", signin_path
I have tried a number of things, but I can't seem to tackle the syntax error. I am sure it is a pretty basic thing for somebody who knows HAML. Any help is much appreciated!
Upvotes: 0
Views: 3513
Reputation: 10251
HAML is indentation based , and the parser can be tricky.You don't need to use - end
in Haml. Use indentation instead.In Haml,a block begins whenever the indentation is increased after a Ruby evaluation command. It ends when the indentation decreases.Sample if else block as follows.
- if condition
= something
- else
= something_else
Upvotes: 2