Module SimpleNavigation::ControllerMethods
In: lib/simple_navigation/rails_controller_methods.rb

Adds methods for explicitely setting the current ‘active’ navigation to the controllers. Since version 2.0.0 the simple_navigation plugin determines the active navigation based on the current url by default (auto highlighting), so explicitely defining the active navigation in the controllers is only needed for edge cases where automatic highlighting does not work.

On the controller class level, use the navigation method to set the active navigation for all actions in the controller. Let‘s assume that we have a primary navigation item :account which in turn has a sub navigation item :settings.

Examples

  class AccountController << ActionController
    navigation :account
    ...
  end

  class AccountSettingsController << ActionController
    navigation :settings
    ...
  end

The first example sets the current primary navigation to :account for all actions. No active sub_navigation. The second example sets the current sub navigation to :settings and since it is a child of :account the current primary navigation is set to :account.

On the controller instance level, use the current_navigation method to define the active navigation for a specific action. The navigation item that is set in current_navigation overrides the one defined on the controller class level (see navigation method). Thus if you have an :account primary item with a :special sub navigation item:

Example

  class AccountController << ActionController
    navigation :account

    def your_special_action
      ...
      current_navigation :special
    end
  end

The code above still sets the active primary navigation to :account for all actions, but sets the sub_navigation to :account -> :special for ‘your_special_action’.

Note 1: As you can see above you just have to set the navigation item of your ‘deepest’ navigation level as active and all its parents are marked as active, too.

Note 2: The specified symbols must match the keys for your navigation items in your config/navigation.rb file.

Included Modules

InstanceMethods

Classes and Modules

Module SimpleNavigation::ControllerMethods::ClassMethods
Module SimpleNavigation::ControllerMethods::InstanceMethods

[Validate]