Module: TabsOnRails::ActionController::ClassMethods

Defined in:
lib/tabs_on_rails/action_controller.rb

Instance Method Summary collapse

Instance Method Details

#set_tab(*args) ⇒ Object

Sets the value for current tab to given name.

set_tab :foo

If you need to manage multiple tabs, then you can pass an optional namespace.

set_tab :foo, :namespace

The set_tab method understands all options you are used to pass to a Rails controller filter. In fact, behind the scenes this method uses a before_filter to store the tab in the @tab_stack variable. For example, you can set the tab only for a restricted group of actions in the same controller using the :only and :except options.

Examples

set_tab :foo
set_tab :foo, :except => :new
set_tab :foo, :only => [ :index, :show ]

set_tab :foo, :namespace
set_tab :foo, :namespace, :only => [ :index, :show ]


102
103
104
105
106
107
108
109
# File 'lib/tabs_on_rails/action_controller.rb', line 102

def set_tab(*args)
  options = args.extract_options!
  name, namespace = args

  before_action(options) do |controller|
    controller.send(:set_tab, name, namespace)
  end
end