TabsOnRails 1.0.0 is now available. TabsOnRails is a simple Rails plugin for creating and managing tabs menu and navigation menu with Ruby on Rails. It provides helpers for creating tabs, an navigation menu in general, with a flexible interface.
The first stable release is now available and I'm also really proud to say that TabsOnRails has 100% coverage of the source code. This doesn't mean the plugin is perfect, nor I can assume this is bug-free. However, the plugin definitely deserves the stable flag.
I have been using TabsOnRails for creating tabs and navigation menu in the last year and I'm really satisfied with how the plugin evolved. I hope you'll enjoy it.
Getting Started
In your template use the tabs_tag
helper to create your tab.
<% tabs_tag do |tab| %>
<%= tab.home 'Homepage', root_path %>
<%= tab.dashboard 'Dashboard', dashboard_path %>
<%= tab.account 'Account', account_path %>
<% end %>
The example above produces the following HTML output.
<ul>
<li><a href="/">Homepage</a></li>
<li><a href="/dashboard">Dashboard</a></li>
<li><a href="/account">Account</a></li>
</ul>
The usage is similar to the Rails route file. You create named tabs with the syntax tab.name_of_tab.
The name you use creating a tab is the same you're going to refer to in your controller when you want to mark a tab as the current tab.
class DashboardController < ApplicationController
set_tab :dashboard
end
Now, for every action defined in DashboardController
, the template will automatically render the following HTML code.
<ul>
<li><a href="/">Homepage</a></li>
<li>Dashboard</li>
<li><a href="/account">Account</a></li>
</ul>
Use the current_tab
helper method if you need to access the value of current tab in your controller or template.
class DashboardController < ApplicationController
set_tab :dashboard
end
# In your view
The name of current tab is <%= current_tab %>.
The open_tag
can be customized with the :open_tabs
option.
<% tabs_tag :open_tabs => { :id => "tabs", :class => "cool" } do |tab| %>
<%= tab.home 'Homepage', root_path %>
<%= tab.dashboard 'Dashboard', dashboard_path %>
<%= tab.account 'Account', account_path %>
<% end %>
<ul id="tabs" class="cool">
<li><a href="/">Homepage</a></li>
<li><a href="/dashboard">Dashboard</a></li>
<li><a href="/account">Account</a></li>
</ul>
Further customizations require a custom Builder (see below).
Installation
You can upgrade/install the library via RubyGems.
$ gem install tabs_on_rails --source http://gemcutter.org
Please note the GEM is now hosted on Gemcutter. If you installed it from GitHub you need to uninstall weppos-tabs_on_rails
and install tabs_on_rails
.
As usual, patches and feedback are welcomed.