Module: SimpleNavigation::ControllerMethods

Defined in:
lib/simple_navigation/controller_methods.rb

Overview

Adds methods for handling the current ‘active’ navigation to the controllers.

On the controller class level, use the navigation method to set the active navigation for all actions in the controller.

Examples

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

class AccountSettingsController << ActionController
  navigation :account, :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_primary_navigation to :account and the current_sub_navigation to :settings.

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).

Example

class AccountController << ActionController
  navigation :account

  def your_special_action
    ...
    current_navigation :special
  end
end

This overrides :account as active navigation for your_special_action and sets it to :special.

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

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



39
40
41
42
43
44
45
46
# File 'lib/simple_navigation/controller_methods.rb', line 39

def self.included(base) #:nodoc:
  base.class_eval do
    extend ClassMethods
    include InstanceMethods
    include SimpleNavigation::Helpers
    base.helper_method :render_navigation, :render_primary_navigation, :render_sub_navigation
  end
end