Rails 高亮当前的菜单

Rails - Easy "active" classes for menu links in Rails
更新于: 2021-11-19 14:43:16
## app/helpers/application_helper.rb
module ApplicationHelper
  def current_class?(test_path)
    return "active" if request.path == test_path
    ""
  end
end

## 添加到 html.erb 文件中
<a href="/" class="nav-link <%= current_class?('/')  %>">