我有一个导航面板。如果我点击它,我希望菜单项的类更改为active
。
%li= { :class => current_page?(admin_roles_path) ? 'active' : nil }
= link_to "Roles", admin_roles_path
但是我收到以下错误:
Haml::SyntaxError in Admin::Roles#index
Showing /sites/freshapp/app/views/layouts/_sidebar.html.haml where line #7 raised:
Illegal nesting: content can't be both given on the same line as %li and nested within it.
答案 0 :(得分:1)
=
之后您不需要%li
,并且您有太多空格/标签。 (Haml是一种嵌套语言,标签/空格的数量很重要)。这样做:
%li{ :class => current_page?(admin_roles_path) ? 'active' : nil }
= link_to "Roles", admin_roles_path
答案 1 :(得分:1)
试试这个(=
之后
%li
不需要%li{ :class => current_page?(admin_roles_path) ? 'active' : nil }
= link_to "Roles", admin_roles_path
{{1}}
答案 2 :(得分:0)
试试这个
%li{ :class => "#{current_page?(admin_roles_path) ? 'active' : nil}"}
= link_to "Roles", admin_roles_path