The easiest way to add tabbed navigation to your Rails app!

Posted by Paolo Mon, 24 Jul 2006 01:09:00 GMT

UPDATE Feb 01, 2007: the Tabnav has been updated in order to work wit Rails 1.2, read this post fom more info.

Hi guys, during our development efforts we needed tabbed navigations. Well, after struggling with the acts_as_wizard plugin (you can find it in the toolbox) we decided to implement yet another rails plugin, and we think this time it’s even easier to use and someway plain cool.

Tabnav it’s so far the easiest way to build tabbed navigation like this:

A basic Tabnav...

The Tabnav Rails plugin provides nice tabbed navigation out of the box

All this magic it’s done by this fragment of code put inside my layout:

<%= start_tabnav :main %>
<%= @content_for_layout %>
<%= end_tabnav %>

Sounds cool? keep reading…

Where does the start_tabnav gets informations for tabs rendering? The :main Symbol let the start_tabnav method know to look for a special MainTabnav class where all the magic happens, so in my model directory I’ve got a main_tabnav.rb file containing something like:

class MainTabnav < Tabnav::Base       
  add_tab do 
    named 'Dashboard'
    titled 'Wooooow! what a wonderful tabbed navigation!'
    links_to :controller => 'dashboard'
  end

  add_tab do 
    named 'Users'
    links_to :controller => 'users'
  end 

  add_tab do 
    named 'Companies'
    links_to :controller => 'companies'
    highlights_on :controller => 'dashboard', :action => 'statistics'
  end 

  add_tab do 
    named 'Admin'
    links_to :controller => 'companies'
    show_if "params[:admin] == true"
  end      
end

This way you can manage your tabs in a view-indipendent manner. The MainTabnav class should be pretty self-explanatory… but let me point out a few nice features:

  • The titled method gives your tabs a html ‘title’ attribute so you can have tooltips over your tab link.
  • The links_to method creates the tab’s link. You can use the same options as the usual ActionView’s url_for. The tab will be automatically highlighted (with the help of a CSS class) if the page you’re viewing matches the links_to options. So if you’re linking to :controller => ‘dashboard’, you can be sure every dashboard’s action will keep the tab highlighted. If you’re linking to :controller => ‘dashboard’, :action => ‘index’ only the index action will highlight it.
  • You can add more highlighting rules using the highligths_on method. This could be useful if you have more than one controller that should highlight the same tab (eg: think about an estimate wizard involving multliple controllers, keeping an ‘estimates’ tab highlighted).
  • You can conditionally choose to show or not show a tab given a certain condition with the show_if method. The string parameter given will be evaluated in the view context, so you can show admin pages tabs only to administrators and so on.

It’s cool! Tell me how to use it!

Install it from your rails base directory with this: ruby script/plugin install svn://svn.seesaw.it/tabnav/tags/0.1

And generate how many tabbed navigations you like with:

ruby script/generate tabnav Main

Of course you can substitute ‘Main’ with the desired prefix of your tabnav class.

Then configure your Tabnav model as you desire and include a start_tabnav/end_tabnav statement in your layout or view files.

Can I customize the generated HTML/CSS?

The tabnav generator will create a partial file inside your view/tabnav directory. There you can customize the html and the inline CSS used by your tabnav. You can move the inline CSS to you stylesheet file too.

Can I nest navigations?

Yes of course, with tabnav you can easily do something like:

Nested Tabnavs

You can easily nest tabnavs. They rely on their own model, partial and CSS stylesheet.

Another little trick…

Last but not least you can have tabbed navigations without having a whole ‘containing box’ using just a:

<%= tabnav :main %>

This way you can do stuff like:

Tabnavs with/without boxes.

You can have just navigation tabs without the whole box attached under them

That’s it right now guys. Hope you find it useful! Don’t forget we need feedback, so feel free to comment on this post or send us a private email.

If you want to keep in touch with further developments you can even subscribe to our rss feed.

This plugin is part of the SeeSaw’s toolbox.

having trouble downloading the plugin? You can install it without subversion:

In vendor/plugins, create directory tabnav. In that directory download end extract this!

Update: Due to a server migration, we’ve moved our repositories to a new location… see this for more info.

Posted in , ,  | Tags , , ,  | 107 comments | no trackbacks

Trackbacks

Use the following link to trackback from your own site:
http://blog.seesaw.it/articles/trackback/839

Comments

  1. Avatar interguycn@gmail.com said 1 day later:

    i can’t install it to my operation system. my operation system is windows 2003. please help me. thank you. this tool is very very cool!

  2. Avatar Scott Sherwood said 1 day later:

    Nice plugin,

    keep up the good work!

  3. Avatar Zeljko Dakic said 3 days later:

    Hi, I would like to use tabnav in my app but your svn server is down for second day at least. Any chance you can make it available somehow?

    Thanks.

    Zeljko

  4. Avatar Paolo Dona said 3 days later:

    It is working right now and we haven’t noticed any downtime so far. Are you sure you’re not behind a firewall or have configuration issues? Anyways we’re setting up a .tar.gz version available via this blog. Leave your email. and I’ll send you the packaged version ASAP

  5. Avatar Zeljko Dakic said 4 days later:

    Thanks. Please, please send me and I will check right away why I can’t get it. Anyone else have such issues?

    Again thanks a bunch.

    Zeljko

  6. Avatar peter Salomon said 6 days later:

    Nice tool!

    Got it working immediately! But how can i use it with grouped controllers? I tried

    links_to :controller => '/admin/infos'

    Links correct, but does not highlight… Moreover, if i´ve been at /admin/infos/somewhere and use a tab to return to /user/anotherone it creates the url /admin/user/anotherone…

    Please tell me it is possible anyway and i´ve made sth wrong…

  7. Avatar Kyle Heon said 6 days later:

    Cool plugin. I have it installed and generated a menu named administration but when I add the code above to my layout file, I’m getting this error:

    undefined method `start_tabnav’

    What did I do wrong?

  8. Avatar Paolo said 6 days later:

    [Peter] I’ve never tried to use it with grouped controllers, and I’m not familiar with them. Try to add an highlights_on :controller => ‘infos’ I’ll dig this issue but if you want take a look into my code and see if something looks wrong.

    [Kyle] try to restart your app, this plugin does not support hot reloading yet.. it’s in my todo list :-)

  9. Avatar Kyle Heon said 6 days later:

    Thanks, restarting the app did the trick. Great plugin. Thanks again.

  10. Avatar Eric Pugh said 7 days later:

    I’ll retiterate that the plugin is great. Maybe a note about the lack of reloading, causing it tripped me up a bit as well! Definitly made a little app I am working on look sharper!

  11. Avatar Zeljko Dakic said 8 days later:

    I just want to thank you guys for creating this plugin. It is time saver and great helper. It does help when you know in advance about how it works, as I couldn’t use it in my app as all tabs use same controller,action pair. Still, I already have idea how this will be great to use in future projects. I also want to thank you for helping me obtain it.

    Keep up the good work.

    Zeljko

  12. Avatar Gregor Melhorn said 9 days later:

    I faced the same problem as Peter, using the controller nested in a module.

    I struggled around with link_to, finally I found out it’s only necessary to add the controller with the module name as a highlight again:

    links_to :controller => ‘companies’ highlights_on :controller => ‘mymodule/companies’

    this works for me, as I’m using the menu only inside the module. Propably this workaround won’t do it if the menu shows up on a page outside the module.

  13. Avatar Jacques said 10 days later:

    Thanks that worked perfectly for me

    links_to :controller => '/admin/login_group'
    highlights_on :controller => 'admin/login_group'

    Lovely Plugin Paulo, thanks :)

  14. Avatar Lucas Efe said 10 days later:

    Is there any way to get the plugin from a http source? I have no access to SubVersion repositories from this location. Thank you Lucas

  15. Avatar Paolo said 10 days later:

    You should be able to download it via http here.

  16. Avatar Carlos Vela said 14 days later:

    A tab like add_tab do named ‘AnyName’ links_to :controller => ‘cursos’ end

    links to /

    Any other string not been ‘cursos’ works.

    Anybody can verify this works or not?

  17. Avatar Mark Richman said 14 days later:

    I set it up, but all I see is Home>

    class MainTabnav < Tabnav::Base add_tab do named ‘Home’ links_to :controller => ‘account’ end end

    add_tab do 
      named 'Products'
      links_to :controller => 'products'
    end
    add_tab do 
      named 'Categories'
      links_to :controller => 'categories'
    end

    Also, inside _main_tabnav.rhtml, the ‘tabs’ array only contains one object:

    tabs.each do |tab|

    Please help!

    Thanks, Mark

  18. Avatar Carlos Vela said 16 days later:

    [Mark] Code must be:

    class MainTabnav < Tabnav::Base
    add_tab do
      named ‘Home’
     links_to :controller => ‘account’
    end
    #MOVED THE END FROM HERE…

    add_tab do
      named ‘Products’
      links_to :controller => ‘products’
    end

    add_tab do
      named ‘Categories’
      links_to :controller => ‘categories’
    end
    end #...TO HERE

  19. Avatar justin wiley said 16 days later:

    Hi,

    I ran the plugin install script: $ ruby script/plugin install svn://svn.seesaw.it/t abnav A /var/www/helpdesk/vendor/plugins/tabnav A ... /var/www/helpdesk/vendor/plugins/tabnav/README Exported revision 38.

    ...seemed to work ok. But when I try to generate, I get:

    ./script/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:147:in `require’: no such file to load—rubygems (MissingSourceFile) from ./script/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:147:in `require’ from script/../config/../vendor/plugins/tabnav/init.rb:1:in `load_plugin’ from ./script/../config/../vendor/rails/railties/lib/initializer.rb:348:in `load_plugin’ from ./script/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings’ from ./script/../config/../vendor/rails/railties/lib/initializer.rb:348:in `load_plugin’ from ./script/../config/../vendor/rails/railties/lib/initializer.rb:158:in `load_plugins’ from ./script/../config/../vendor/rails/railties/lib/initializer.rb:158:in `load_plugins’ from ./script/../config/../vendor/rails/railties/lib/initializer.rb:102:in `process’ from ./script/../config/../vendor/rails/railties/lib/initializer.rb:42:in `run’ from ./script/../config/../config/environment.rb:13 from ./script/../config/../vendor/rails/railties/lib/commands/generate.rb:1 from script/generate:3

    ...is there some missing dependancy that needs to be installed beforehand? Im using:

    Ruby version 1.8.4 (i486-linux) Rails version 1.1.2

    Thanks,

    Justin

  20. Avatar justin wiley said 16 days later:

    In fact, tabnav apparently poisoned the plugin init process to the point where I could no longer fire up the server.

    $ => Booting WEBrick… ./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:147:in `require’: no such file to load—rubygems (MissingSourceFile) from ./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:147:in `require’ from script/../config/../vendor/plugins/tabnav/init.rb:1:in `load_plugin’ ...and so on

    Deleting tabnav directory fixes the problem. $ rm -rf tabnav $ => Booting WEBrick… => Rails application started on http://0.0.0.0:3000 ...

  21. Avatar Carlos Vela said 16 days later:

    In vendor/plugins/tabnav/init.rb:
    require ‘rubygems’
    require ‘active_support’
    require ‘action_view’
    require ‘tabnav_core_extensions’
    require ‘tab’
    require ‘tabnav’
    require ‘application_helper_extension’

    For message no such file to load—rubygems(MissingSourceFile), it seems you haven’t install rubygems??

    Must be installed all require in init.rb

  22. Avatar Glenn said 18 days later:

    Hi,

    I am running on edge rails. As of today, my app broke and is failing on tabnav. It was working fine before… ???

    The strange thing is, when I start mongrel server, I can load any page in my app one time. Then, if I reload or go to a new page it fails immediately until I restart the web server.

    I renamed the vendor/rails edge rails dir to rails_foo and restarted the web server and I can view pages with no problem with tabnav (primary rails is 1.1.5 as of today and this works).

    Here is the stack trace first showing the successful load (controller => about), and then the failure (controller => about, action => beta):

    Here is the main error:

    ActionView::TemplateError (undefined method `tabnav’ for #<#:0×3847a58>) on line #5 of app/views/layouts/_main_menu.rhtml: 2: 3: 4: <!- TABNAV : Start inclusion of TabNav Tab Menu RoR plugin -> 5: <%= tabnav :main %> 6: <!- TABNAV : End -> 7:

    Here is the trace for when it fails:

    ActionView::TemplateError (undefined method `tabnav’ for #<#:0×3847a58>) on line #5 of app/views/layouts/_main_menu.rhtml: 2: 3: 4: <!- TABNAV : Start inclusion of TabNav Tab Menu RoR plugin -> 5: <%= tabnav :main %> 6: <!- TABNAV : End -> 7:

    #{RAILS_ROOT}/app/views/layouts/_main_menu.rhtml:5:in `_run_rhtml_47app47views47layouts47_main_menu46rhtml'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:317:in `compile_and_render_template'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:293:in `render_template'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:252:in `render_file'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:267:in `render'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/partials.rb:59:in `render_partial'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:26:in `benchmark'
    c:/apps/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
    c:/apps/ruby/lib/ruby/1.8/benchmark.rb:307:in `realtime'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:26:in `benchmark'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/partials.rb:58:in `render_partial'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:279:in `render'
    #{RAILS_ROOT}/app/views/layouts/application.rhtml:60:in `_run_rhtml_47app47views47layouts47application46rhtml'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:317:in `compile_and_render_template'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:293:in `render_template'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:252:in `render_file'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/layout.rb:254:in `render_without_benchmark'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:50:in `render'
    c:/apps/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:50:in `render'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:981:in `perform_action_without_filters'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:363:in `perform_action_without_benchmark'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue'
    c:/apps/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/rescue.rb:80:in `perform_action'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:408:in `process_without_filters'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:372:in `process_without_session_management_support'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/session_management.rb:114:in `process'
    #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:319:in `process'
    #{RAILS_ROOT}/vendor/rails/railties/lib/dispatcher.rb:41:in `dispatch'
    c:/apps/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel/rails.rb:73:in `process'
    c:/apps/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:551:in `process_client'
    c:/apps/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:550:in `process_client'
    c:/apps/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:636:in `run'
    c:/apps/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:636:in `run'
    c:/apps/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:625:in `run'
    c:/apps/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:956:in `run'
    c:/apps/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel.rb:955:in `run'
    c:/apps/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/bin/mongrel_rails:127:in `run'
    c:/apps/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/lib/mongrel/command.rb:199:in `run'
    c:/apps/ruby/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3-mswin32/bin/mongrel_rails:235
    c:/apps/ruby/bin/mongrel_rails:18

    Rendering C:/Data/subversion/rubyrails/packmaps/trunk/packmaps/config/../vendor/rails/actionpack/lib/action_controller/templates/rescues/layout.rhtml (500 Internal Error)

  23. Avatar enric said 18 days later:

    Hello thanks for the plugin. Unfortunately, it’s not working for me

    “ruby script/plugin install svn://svn.seesaw.it/tabnav”

    says it installs (as in no errors) but there is no feedback of any kind, either.

    Then “ruby script/generate tabnav Main”

    says, Couldn’t find ‘tabnav’ generator.

    ?? Tried restarting server. No go. thanks.

    sorry, newbie. Do I need to install something to get svn:// from plugins command?

  24. Avatar enric said 18 days later:

    Answered my own question. Yes, I do. :)

    thanks…

  25. Avatar james said 24 days later:

    hmm… want to share what this “something” was that you had to install, enric? :)

  26. Avatar Jam said 28 days later:

    Hi Paolo!

    Very nice plugin! Is it possible to arrange tabs vertically on the left/right side of main_content area?

    How can I do it?

  27. Avatar Michele said 28 days later:

    Sure you can! Tabnav is just a list of <li> element, any layout customization can be made via CSS like any other html list.

  28. Avatar Jam said 28 days later:

    Great! I’ll keep playing around :)

  29. Avatar Stuart said 30 days later:

    Two questions -

    1- I have 2 types of users for my app. I’d like one tabnav set for the first type of user and another tabnav for the second type of user. Is this possible ? In other words each user has different functions available to them.

    2- Should / could I treat each tab as a div where within would like either an rhtml view or partial / or rjs page ?

    TIA Stuart

  30. Avatar Michele said 32 days later:

    [1] Yes, just using a proper boolean condition with show_if in the model file; something like:

      add_tab do 
        named 'Admin'
        links_to :controller => 'companies'
        show_if "params[:admin] == true" 
      end      
    

    Take a look at the second code fragment of the original post.

    [2] Actually tabs are rendered like an HTML list, but you easily use another behaviour redefining the partial in /app/view/tabnav/.

  31. Avatar Gareth said 36 days later:

    Hi Guys,

    Is there a way to use TabNav and not put it in the layout?

    It seems like you would have to be able to do that to be able to do the nesting of tabs.

    Thanks

    Gareth

  32. Avatar David Jones said 41 days later:

    Hi Michele,

    I was trying to work out a way to dynamically add tabs. For example, if you had a portfolio tab which was a menu list of all your portfolio entries, you might want to iterate through all the entries, but the options for each tab as essentially the same.

    Maybe an add_collection_of_tabs method could work well.

    
    add_collection_of_tabs(Pages.find(:all), {
      named item.title
      links_to :controller => 'pages',
               :action => 'show,
               :id => item.id
      highlights_on :controller => 'pages',
                    :action => 'show,
                    :id => item.id
    })
    
    # Method signature could be something like...
    add_collection_of_tabs(collection, &block)
    
    

    However, I have managed to get the same functionality to work with the current plugin code:

    
    class PortfolioTabnav < Tabnav::Base    
    
      def initialize
        add_collection_of_tabs(PortfolioEntry.find(:all))
      end
    
      def add_collection_of_tabs(collection)
        self.tabs ||= []
        for item in collection
           self.tabs << Tabnav::Tab.new do
             named item.title
             links_to :controller =>"/" 
             highlights_on :controller => 'portfolio_entries',
                           :action => 'show',
                           :id => item.urlname
           end
        end
      end
    end
    
    

    So just as a suggestion, perhaps you should add some sort of method which allows people to add a collection of tabs.

    Thanks for the useful plugin, David.

  33. Avatar Bèrto 'd Sèra said 42 days later:

    Neat job! I wish the salted passwords gen was this easy to install ;) BTW, if you use WEBrick you need to restart the server to see the changes you make in the MainTabnav class. But that’s as much surprises as you can get :)

  34. Avatar Akhil Bansal said 43 days later:

    This is what I am trying to do in my current project. Thanks Paolo, I am going to use this plugin.

  35. Avatar umang@mac.com said 45 days later:

    I just downloaded the Plugin from the http source and unzipped on a Mac to a TabNav folder. Where do I place this folder or wht else do i need to do to get it working.

  36. Avatar Akhil Bansal said 46 days later:

    How to make rounded tabs using this plugin

  37. Avatar Akhil Bansal said 51 days later:

    How can I highlight tab through RJS?? Any Idea????

  38. Avatar Hari said 53 days later:

    Hi I am not able to access the svn server . At least I get no message from the script\plugin

    I downloaded the .tar.gz file but I am not able to find instructions on how to install it . Can u help me

    Regards Hari

  39. Avatar Michele said 55 days later:

    Sorry for the dalay of this answer but we had huge problems with spam filters during these days.

    [for umang@mac.com + Hari]

    Installation of the .tar.gz/.zip is very basic: decompress the archive into the vendor/plugins/ directory of your rails project and follow the tutorial .

    [for Akhil Bansal]

    Rounded tab can be obtained using CSS/HTML: take a look to the answer to the Stuart’s problem, 9/10 post ago. Do you really need RJS? ;-)

    [for Bèrto ‘d Sèra]

    Thank you so much!

  40. Avatar Shauna said 57 days later:

    I’m having trouble figuring out how to implement Tabnav in my fledgling app.

    I have a main page which I do not want to convert to tabs. But when I go to edit, say, a person record or a pets record, I want a tabbed form to open with a separate clump of info to edit on each tab. The person edit would open up a set of person-related tabs, and the pet edit would open up a set of pet-related tabs.

    I have a layouts/application.rb but putting the start_tabnav and end_tabnav there cause multiple sets of the same tabs to appear. I could make copies of the application.rb and just change the start_tabnav line of each to point to the correct set of tabs for that table. But that wouldn’t be very DRY, would it?

    So how do I specify a layout for person that can have <%= start_tabnav :main %> <%= @content_for_layout %> <%= end_tabnav %> but still use application.rb as a wrapper?

    Thanks…

  41. Avatar Akhil Bansal said 58 days later:

    Yes, I still need to highlight tabs in RJS Calls… How could i do that…....

  42. Avatar Thats good said 68 days later:

    Thanks for your plugin

  43. Avatar Peter Salomon said 71 days later:

    … is it possible to rename the tabs to support different languages?

  44. Avatar Peter Salomon said 71 days later:

    … is it possible to rename tabs to support different languages?

  45. Avatar How can i specify 2 or more conditions using "show if" said 71 days later:

    How Can i have 2 or more conditions for “show_if”.

    Regards, Ashwin

  46. Avatar David Lelong said 73 days later:

    Can I include an :id tag that populates dynamically? I’ve been able to include a hardcoded id without any problems, but when I include a variable from my controller, it is not being populated.

    Thanks,

    David

  47. Avatar Paolo said 74 days later:

    [Ashwin] How can i specify 2 or more conditions using “show_if”?

    Just try with:
    show_if "current_user.admin? or params[:id]==3" 
    
  48. Avatar Paolo said 74 days later:

    [Peter Salomon] is it possible to rename tabs to support different languages?

    Right now it’s not possible by the plugin itself. Take a look to i18n tools for Rails and try to apply them on the Tabnav code. PS: don’t forget to let us know what you’ll discover ;-)

  49. Avatar Paolo said 74 days later:

    [Akhil] highlight tab through RJS?

    You can set the CSS class of an HTML element via RJS/prototype calls, just set the CSS class to ‘active’ on the dom id you need to highlight.

  50. Avatar Michiel said 77 days later:

    I’m getting the same ‘undefined method’ error in my rails app.

    The ApplicationHelper methods don’t seem to get loaded. If I drop them directly into application_helper.rb it works just fine. I’ll look into it later.

  51. Avatar matthi said 81 days later:

    Hi Paolo, nice stuff

    Anyway, I have tried for hours to set the @name var accordingly to the highlighted? method.

    So, what I would need is to set a different name if the tab is highlighted.

    Any atempt so far resulted in some strange “error”, that way, that the @name got changed, but once a given menutab clicked, the name stayed changed…

    Actually what I need is the following:

    instaed of just having a class=”xyz” for the a-tag, what I would like to have is a kind of wrapper around the “name”, e.g. name and on highlight name

    So, as the url_for / link_to etc methods dont offer this kind of stuff i pass this directly within the @name var..

    Any simple way to get this running ???

    Regards

    matthi

  52. Avatar Paolo said 87 days later:

    We’re working on dynamic names, titles, links etc. This way you will able to pass a Proc object to named, titled,... Just have a little bit of patience as we’re buried by another project right now.

    Paolo

  53. Avatar Mark Ricard said 93 days later:

    When I run this within the app’s root directory “ruby script/plugin install svn://svn.seesaw.it/tabnav” it appears to install correctly because I see no errors or warnings. Just a blank prompt. But when I try to do this “ruby script/generate tabnav Main” from the app root, I get “Couldn’t find ‘tabnav’ generator” ???

  54. Avatar Mark Ricard said 93 days later:

    After downloading the tar and unpacking it in the vendor/plugins directory, then calling generate it worked. Something must be wrong with the install command line and the url.

  55. Avatar marco said 101 days later:

    Do I really have to restart every time Webrick after Tabnav-Model-Changes?

  56. Avatar Akhil Basnal said 105 days later:

    Hi, Is this work with named URL’s. I tried this: add_tab do named ‘Home’ links_to home_url end

    It not worked. Is there any work around for that.

  57. Avatar Cid Dennis said 110 days later:

    Great plugin. But one question:

    How do I have the link contain parameters. So for example if I have a Order Tab that shows an order how do add the order Id to the tab so when when it is clicked I can get the id.

    Thanks

  58. Avatar Cid Dennis said 110 days later:

    I figured it out. I just changed the generated template to change the link parameter to add the params I needed.

  59. Avatar Paolo said 113 days later:

    We’re about to release a new version of the plugin that supports dynamic parameters. I cannot do it right now because we’re moving the svn to a new server, but I promise we’ll do it in a few days.

    [marco] Yes you have to restart the container, I have no time to fix the reloading issue but if you want to dig into it and submit a patch I’ll appreciate it for sure! The same goes for named routes.

  60. Avatar Akhil Basnal said 116 days later:

    Is the new version is restful?

  61. Avatar Mark Ricard said 117 days later:

    The link to download the tabnav code on your website does not work – it times out. Also, the svn does not seem to work for me either. I have never been able to get the svn to work, but I have gotten the download to work before. Is it down?

  62. Avatar Michele said 121 days later:

    As you can see in this post, we are migrating our servers… public svn repo is ready to use while the archives are not. Thank you for your patience!

  63. Avatar kathys39 said 130 days later:

    I’ve got navtabs working – sortof – pretty cool actually. My problem is I have a header with logo that displays (using a css header), then the NavTabs, then my content. In between the header and NavTabs, then again between NavTabs and main content there is whitespace. I do not have any of these things set with margins in my css file. What else am I missing? I’d like to Tabs to butt up against my header and have my main content start right below that! Any ideas?

  64. Avatar Paolo said 135 days later:

    You probably should edit the generated css file under app/view/tabnav/_your_tabnav.rhtml.

    There are margins set there.

  65. Avatar Ted Price said 137 days later:

    Yeah I thought it was going to take me at least 10 minutes to find and implement a tab-solution to a big ole rails project at my company. It took me 3, I am going to go have a cigarette with the spare 7. Sweet.

  66. Avatar Kadoudal said 157 days later:

    Merry Xmas to all readers…

    Super plugin… easy to install and to use ..but I’ve been searching around how to pass au :id in the link wo any success… (finally hacking it with a session variable.. but not very RoR…)

    so it’s stil an open issue for me :

    in my view how to pass the @user as an id ? <%= start_tabnav :profil %>

    to get it in the profil_tabnav.rb links_to :controller => ‘profils’, :action => ‘show’, :id => @user

    as my action ‘show’ needs an :id…

    thanks for your lights

    kad

  67. Avatar Paolo Dona said 158 days later:

    Try with: links_to proc {{:controller => 'profils', :action => 'show', :id => @user}}

  68. Avatar remco said 158 days later:

    hi, thanks for the great plugin, the trick with links_to proc{{.... for dynamic links doesn’t work for me, is there any other workaround? that would be great,

  69. Avatar Paolo said 166 days later:

    what error are you getting? are you using the latest version?

  70. Avatar Kadoudal said 169 days later:

    links_to proc

    working well…. thanks a lot ! great plugin saving time !!

  71. Avatar Jack said 177 days later:

    TabNav blew up my computer. Awesome TabNav ! Little things like this allow me to focus on the enjoyable aspects of programming like writing “synchronized dual turbo server blitzing.” Or as it’s acronymn SDTSB.

  72. Avatar Bill said 179 days later:
    So, I am trying to embed tabs, I am using
    class CustomerTabnav < Tabnav::Base
      add_tab do
        named 'Info'
        links_to proc {{:controller => 'profils', :action => 'show', :id => @user}}
      end
    end
    
    
    and my tabs dissapear. If I use:
    links_to :controller => 'customers', :action => 'show_info'
    
    as my link, it works. However, I do need the ID and don’t understand what I am missing…. Any takers?
  73. Avatar Bill said 179 days later:
    Now, I’m closer with:
        add_tab do
            named 'Overview'
            links_to {{ :controller => 'customers', :action => 'show', :id => @customer }}
        end
    
        add_tab do
            named 'Info'
            links_to {{ :controller => 'customers', :action => 'show_info', :id => @customer }}
        end
    
    but all of my links in my html point to:
    http://localhost:3000/customers/show/1
    
    when you can see in my links_to definitions, I pointed them to different places.
  74. Avatar Bill said 180 days later:

    Note to those who follow:

    updated to trunk, and it works!
    thus, instead of the svn import command above, save yourself the grief and days of troubleshooting, and use this svn instead: script/plugin install svn://svn.seesaw.it/tabnav/trunk
  75. Avatar matthibcn said 182 days later:

    updating to 1.2.1 from 1.1.6 crashed my application, I am usign tabnav for a tabbed navigation, without container or stuff…

    Is there anything i have to change for 1.2.1 ??

    undefined method `tabnav’ for #<#:0×4dab278>

    There has never been a prob under 1.1.6

    I will figure it out, just am asking in case you came to the same prob before and could help me and probably others out

    Anyway, very nice puligin

    keep on the good work matthibcn

    ps: would be nice if this comments would be DATED instead of using “150 days later”, “180 days later”...

  76. Avatar Daniel Smedegaard Buus said 184 days later:

    Hi! I’m trying to use this on a display page for books.

    The tabs are part of the overall page, and a way to avoid cluttering the page with all the information about the book in one big chunk.

    So, I’ll have three tabs, “Description”, “Table of Contents”, and “Reviews”.

    All link to the same action, like:

    add_tab do 
      named         'Description'
      links_to      :action => 'show', :show => 'description'
      show_if       '!@item.descr.blank?'
      highlights_on { (params[:show] == 'description' || params[:show].blank?) }
    end

    Only thing is, the :show => parameter works fine, and the page is redrawn properly, displaying the right tab.

    Except: All tabs are of the “active” class, because the links_to points to the same action in the same controller.

    I’d like an option like, highlights_on_and_only_on { myproc }, so that I can have just one tab use the “active” class.

    Do I make any sense?

    Thanks for a nice plugin! :)

  77. Avatar Daniel Smedegaard Buus said 184 days later:

    Ah! Got it!

    It should be,

    highlights_on :show => ‘description’, :show => nil

    Cheers :)

  78. Avatar Stan said 201 days later:

    Anyone know what causes this: /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:376:in `new_constants_in’: You have a nil object when you didn’t expect it! (NoMethodError) You might have expected an instance of Array. The error occurred while evaluating nil.empty? from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:202:in `load_file’ from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:94:in `require_or_load’ from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:248:in `load_missing_constant’ from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:452:in `const_missing’ from script/../config/../vendor/plugins/tags/acts_as_attachment-1.1.6/init.rb:6:in `load_plugin’ from /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/initializer.rb:401:in `load_plugin’ from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings’ from /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/initializer.rb:401:in `load_plugin’ ... 15 levels… from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:495:in `require’ from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:342:in `new_constants_in’ from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:495:in `require’ from script/generate:3

    script/generate tabnav rss_editor ./script/../config/boot.rb:28:Warning: require_gem is obsolete.  Use gem instead.
  79. Avatar Stan said 201 days later:

    Found the culprit:

    `const_missing’ from script/../config/../vendor/plugins/tags/acts_as_attachment-1.1.6/init.rb:6:in

  80. Avatar Ary said 203 days later:

    Hey! Where can I download the right version for rails 1.1.x using http?

  81. Avatar Michele said 204 days later:

    I’ve just updated the download page with the new versions

  82. Avatar Kelly said 256 days later:

    Using IE7 with tabnav, the tabs float about 10 pixels above the content box. Using FF or IE6, all is fine. Anyone else seeing this?

  83. Avatar Strafverteidiger München said 271 days later:

    I’ll keep playing around :-) Thanks!

  84. Avatar bang bros said 275 days later:

    I am here to notify you that in the end of April 2007 will be Ruby and WP community party at NY, US.

  85. Avatar Jignesh said 278 days later:

    I’m not able to make it work. I’m using InstantRails. Its giving me ‘undefined method `start_tabnav’ for #<#:0×47cc758>’ error. I’ve extracted the tar file under vendor/plugins dir of my app. Please help !!!!

  86. Avatar Jignesh said 278 days later:

    I managed to get it up running but facing new problem. How to use ‘links_to’ to specify the content div as watever :action i’m setting rite shows up the content on new page without the tabs?

  87. Avatar conradwt@gmail.com said 283 days later:

    Hi, after adding the appropriate link_to, the tabs disappear after selection.

  88. Avatar conradwt@gmail.com said 283 days later:

    Hi, I was thinking that it would be cool if I could simply use render instead of links_to. I say this because I want to do is render content for a tab. What do you think about this?

  89. Avatar Dipesh said 284 days later:

    Hi, Thanks for such a great plugin. I have been trying to dynamically add a tab into the tabnav. What user does is, clicks on a link on a page, this should rout the resquest to an action in a controller. This action should have the logic to dynamically create a control. Now had some success with this, I did something like this:

    def show @group = g = Group.find(params[:id]) ListTabsTabnav.add_tab { named g.name; links_to :controller => “groups”, :action => “show”, :id => g.id } end

    This works fine as long as FastCGI is not on. When I put my app on FastCGI, problems begins. Once the tab is dynamically created it just stays there forever. Even if i change page. I have to kill the fcgi dispatcher, to remove it.

    Is there some better way to handel this problem?

  90. Avatar Tom Meinlschmidt said 286 days later:

    to “peter Salomon”... with grouped controllers

    just use

    add_tab do named ‘Albums’ links_to :controller => ‘admin/albums’ end

    without starting ”/” in links_to .. it works :)

  91. Avatar Mo said 361 days later:

    this plugin is pretty cool but I have a bit of a problem.

    I want the ability to assign the list item with the class ‘active’ as well when I indicate highlighting. I need this so my tab looks cool when highlighting as i’m doing the curvy image thing.

    Not sure how i could do that without hacking your code.

    Thanks

  92. Avatar Fiesa said 374 days later:

    nice plugin! I wonder if it would be possible to add a image next to each tab-title? First try was to modifythe html-list-tag in …_tabnav.rhtml like this:

      didn’t work so far, am not that experienced with rails or html :-(

      Anyone has a idea how to make it work?

      Thanks

  93. Avatar Fiesa said 374 days later:

    hum? last comment seemed to miss the code:

  94. Avatar Fiesa said 374 days later:

    hmm ok, this seems not loving to embed html-tags, so third try without tags: ul id=”order_tabnav” style=”list-style-image:url(/images/list_icon.gif)”

    :-)

  95. Avatar Rob said 375 days later:

    My project requires rounded tabs, so I’m trying to modify the default views.

    The generated rhtml partials appear to be empty (other than a comment).

    I’ve added code to the partials, but the partials are not having any effect. Nor are they even being called.

    How do I change from a simple list to something of my own devising?

  96. Avatar Cássio said 392 days later:

    Hi there,

    after generate a tabnav inside a folder:

    #./script/generate tabnav dir/model

    when a i call it in the view, like this:

    start_tabnav :model

    after that, this error appears:

    /lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:477:in `const_missing’: uninitialized constant Symbol::ModelTabnav

    this worked in the previous version, because i tested…but in the 1.2 it doesn’t work in the same way…

    how do i call a tabnav, that is inside in a directory with the new tabnav version (1.2)?

  97. Avatar Matt said 398 days later:

    I’m new to Rails, but this plugin is going to save me a lot of work. Thanks for putting this together.

    I need to pass in an id to build the links for each tab. How does one reference request parameters from the TabNav extension class?

  98. Avatar Matt said 398 days later:

    Nevermind. I got it working from one of the commments above. Thanks.

  99. Avatar Rv said 405 days later:

    Hi. How to highlight tab with more then one controller? Sth like highlights_on :controller=> ‘admin/one’, :controller => ‘admin/two’ ?

  100. Avatar arf said 436 days later:

    What’s this plugin have over the one liner tab helper described in http://www.vaporbase.com/postings/A_tab_helper_that_works_for_me ?

  101. Avatar qwe said 458 days later:

    Yeah this plugin didnt work for me. Acted like it installed just fine, but when i ran the generator, got a “Couldnt find tabnav generator” error message! Keep up the good work guys

  102. Avatar ernesto73@ono.com said 525 days later:

    I’ve the same problem that Jignesh, matthibcn, Michiel, ...

    undefined method `tabnav’ for #<#:0×4789cb4>

    Do you know de solution?

    thanks,

    ern.

  103. Avatar Win said 542 days later:

    This is a great plugin! Have you thought about creating one for ajax hooks?

  104. Avatar Kitty said 543 days later:

    I want student name in top of page & tabs like edit & show with that students id

    try to work with proc but gives an error

    Showing app/views/tabnav/_student_tabnav.rhtml where line #61 raised

    :You must set a page before calling this method

    (error on line #61 )

    58:

      <% 59: tabs.each do |tab| 60: html_opts = {} 61: html_opts[:class] = ‘active’ if tab.highlighted?(params) 62: html_opts[:title] = tab.title if tab.title 63: if eval(tab.condition) -%> 64:
    • <= link_to tab.name, tab.link, html_opts ->
    • <%

    Trace of template inclusion: /app/views/student/tabs.rhtml

    My tabs page is
    <%= tabnav :student %>

     name: <%= @student.name %>

    Please any one help me

  105. Avatar manoharkundety@gmail.com said 626 days later:

    Hi Guys,right now I am working on Tabs . I got them but I am having a problem in it. It is like this : whenever I click on the Tab it is navigating to the controller’s index method . Here I want the data of the Tab with respect to its clicking .And help me in writing the Actions with respect to Tabs. Hope you all understood my problem and please help in fixing this .

    Thanks & regards , Manohar manoharkundety@gmail.com

  106. Avatar Steve said 662 days later:

    [marco and paolo]

    You can reload the tabnav.rb file without restarting the server the same way you reload models, by simply adding “include Reloadable” to it…

    class ExampleTabnav < Tabnav::Base include Reloadable

    add_tab do
      blah
    end

    end

  107. Avatar Steve said 663 days later:

    Of course that only works in the development environment. I ended up having to just do the dynamic tabs manually. Sorry, didn’t have time to go in and figure it out this time…

Comments are disabled


SeeSaw srl - Via Monte Pasubio, 8 37126 Verona - tel +39 045 4857457 fax 045 4851151 P.Iva 03609790237