TabNav Plugin

From NHRubyWiki

Jump to: navigation, search

TabNav is a Ruby on Rails plugin that allows you to easily generate HTML/CSS navigation tabs in your Rails app. It uses a very clean, modular design and allows a great deal of customization if you don't like its defaults.

To get started with the TabNav plugin, go into your Rails project directory and run:

ruby script/plugin install svn://svn.seesaw.it/tabnav/trunk

At the time of this writing, version 83 was available from the repository. Tip: remember to restart your application server (webrick/mongrel/etc.) after installing a new plugin.

Now decide what you want to name your navigation tab setup. You can have as many TabNav configurations as you like:

ruby script/generate tabnav Main

This would generate the files main_tabnav.rb in your models directory, and _main_tabnav.rhtml in your views/tabnav directory. We'll use this example in the explanations below.

app/models/main_tabnav.rb
This is the main file where you'll set up the name of each tab and configure where each tab links to.
app/views/tabnav/_main_tabnav.rb
This is a view partial which controls the CSS used for the navigation tabs. You can modify this easily to match your site's visual style.

Then to insert your navigation tabs in a view or layout, include the following code:

<%= start_tabnav :main %>
Your own content can go here...
<%= end_tabnav %>

That's the bare basics of using TabNav. For more info, see the following Seesaw blog posts:

TabNav was demonstrated during the June 2007 meeting of NHRuby.org. Both Scott Garman and Nick Plante have used it, so if you have any questions about it, feel free to ask on our discussion email list.

Personal tools