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 :account, :special
  end
end

The code above still sets the active primary navigation to :account but also sets the sub_navigation to :special for ‘your_special_action’.

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