PHCDevworks Active Menus for Rails 7 (Add Active Class to Menus)

PHCDevworks Active Menus Rails 7 engine with helpers to add active class to menus.

  • Easily add an active class to menu items based on the current controller.
  • Effortlessly add an active class to menu items based on the current action.
  • Seamlessly add an active class to menu items based on both the current controller and current action.

Step 1 - Add PHCDevworks Active Menus to your gemfile

gem 'phcdevworks_active_menus'
bundle install

Step 2 - Load Helpers in the Application's Controller

Add the line of code below into your app/controllers/application_controller.rb (application's controller file).

helper PhcdevworksActiveMenus::Engine.helpers

How to Add Active Class Based on Controller Only (Often used for main menu items with sub-menus.)

Add the line of code in between div class tag.

<div class"<%= phc_menu_active_controller("ExampleControllerName") %>">

How to Add Active Class Based on Action Only (Often used for submenu items.)

Add the line of code in between div class tag.

<div class"<%= phc_menu_active_action("ExampleActionName") %>">

How to Add Active Class Based on Controller and Action (Used if you need to get specific.)

Add the line of code in between div class tag.

<div class"<%= phc_menu_active_action_controller("ExampleControllerName", "ExampleActionName") %>">

Status

Gem Version Publish to Github.com Publish to Rubygems.org