使用current_page在HAML中激活链接?

Bar*_*acs 1 ruby haml ruby-on-rails

所以我得到了这个糟糕的代码(当链接不是根路径时,链接会消失.):

    = link_to "News", root_path, class: "active" if current_page?(root_path)
Run Code Online (Sandbox Code Playgroud)

当current_page是root_path时,我想建立链接类.active.

试图找到Rails方式

jvn*_*ill 5

class在括号中包含选项

= link_to "News", root_path, class: ("active" if current_page?(root_path))
Run Code Online (Sandbox Code Playgroud)