TabsOnRails is a simple Rails plugin for creating and managing Tabs in Rails projects. It provides helpers for creating tabs with a flexible interface.
The release 0.3.0 is now available as a GEM. The most important feature is the concurrent tabs support, also known as multi-tabs or namespaces. Namespaces enable you to create and manage tabs in parallels. Let me show you an example.
Let's assume your application provides a first level navigation menu with 3 elements: :home
, :dashboard
, :projects
. The relationship between your tabs and your controllers is 1:1 so you should end up with the following source code.
class HomeController
set_tab :home
end
class DashboardController
set_tab :dashboard
end
class ProjectsController
set_tab :projects
def first; end
def second; end
def third; end
end
The project controller contains 3 actions and you might want to create a second-level navigation menu. This menu should reflect the navigation status of the user in the project page.
Without namespaces, you wouldn't be able to accomplish this task because you already set the current tab value to :projects
. You need to create a concurrent navigation menu and uniquely identify it with a custom namespace.
Let's call it :navigation
.
class ProjectsController
set_tab :projects
# Create an other tab navigation level
set_tab :first, :navigation, :only => %w(first)
set_tab :second, :navigation, :only => %w(second)
set_tab :third, :navigation, :only => %w(third)
def first; end
def second; end
def third; end
end
That's all you need to do. And you can create an unlimited number of namespace as long as you use an unique name to identify them.
The default namespace is called :default. Passing :default as name is the same as don't using any namespace at all. The following lines are equivalent.
set_tab :projects
set_tab :projects, :default
Namespaces supports all the other features already available in TabsOnRails including custom Builders for your Rails tabs. See the documentation page for further information.
You can install/upgrade TabsOnRails by running
$ gem install tabs_on_rails