所以我得到了这个错误的代码(当它不是根路径时链接就消失了。):
= link_to "News", root_path, class: "active" if current_page?(root_path)
当 current_page 是 root_path 时,我想使链接的类 .active。
试图找到 Rails 之道
最佳答案
将 class
的选项括在括号中
= link_to "News", root_path, class: ("active" if current_page?(root_path))
关于ruby-on-rails - 使用 current_page 在 HAML 中激活链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16058502/