Tabnav for Rails 1.2

Posted by Paolo Thu, 01 Feb 2007 06:43:00 GMT

(If you’re looking for tabnav documentation click here!)

Hi guys, we have just released an updated version of the Tabnav. Now it should work well with the brand new Rails 1.2. What have we done then?
  • Refactored the plugin to better match the usual plugin Module/Class structure (inspirated by simply_helpful).
  • Removed the Reloadable support, and fixed the code to make it work with the new Rails dependency mechanism.
  • Added support for restful routes inside tabs definition.
  • Fixed a bug that cached evaluated Proc(s) after the first call in production environment.
  • Moved tabnav design logic out of the generated partial, it now contains only the css (you can of course move it to your stylesheet and delete the partial now)
A sample of the new code you can write is:
class PostsTabnav < Tabnav::Base          
    add_tab do 
      named 'Posts list'
      links_to proc { hash_for_posts_path }
    end

    add_tab do 
      named 'New post'
      links_to proc { hash_for_new_post_path }
    end

    add_tab do 
      named proc{ "Show: " + @post.title }
      links_to proc{ hash_for_post_path(:id => @post.id) }
      show_if proc{ !@post.nil? && !@post.id.nil? }
    end

    add_tab do 
      named proc{"Edit: " + @post.title }
      links_to proc{hash_for_edit_post_path(:id => @post.id)}
      show_if proc{ !@post.nil? && !@post.id.nil? }
    end
end

This version is still young so please report any problem you encounter with it. You can install this version with ruby script/plugin install svn://svn.seesaw.it/tabnav/trunk. If you’re still using Rails 1.1.X please download the old version with ruby script/plugin install svn://svn.seesaw.it/tabnav/tags/0.2.

Note: previously generated Tabnav models are still compatible, just remember to remove the include Reloadable line. Unluckily the new generated partials are different so, you have to regenerate them :-(.

If you want to dig more you can download a lousy sample app here: svn://svn.seesaw.it/tabnav_testapp/trunk.

Other new features are on the way so stay tuned! btw feedback is very appreciated, as usual.

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

Trackbacks

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

Comments

  1. Avatar Rick Martinez said 4 days later:

    Why’d you move the HTML logic out of the partial? I would think it would make more sense to make the HTML more customizable just in case. (In my case, I like to make the <li> tag’s class “active” instead of the <a>.) And you never know when someone needs some special HTML for their tabs so I would assume it makes more sense to keep it in the partial.

  2. Avatar Paolo said 5 days later:

    Hi Rick, we moved the code out of the partial because it was not DRY, and it caused a lot of issues if we wanted to change the code as people was forced to rebuild old partials. You can still override the helpers in your application_helpers.rb to modify it.

  3. Avatar k said 8 days later:

    Hi, visited tabs stay highlighted using the newest version.

    Since Tab.html_options( options=nil ) acts as a getter method if called without parameters, it can’t be used in tabnav_helper.rb to reset @html_options.

    Adding @html_options = {} to Tab.highlighted? works for me.

  4. Avatar Rick Martinez said 9 days later:

    What do you think about adding external link support? This would be great for people who use this for their navigation links and want to have an external link there without work arounds.

  5. Avatar D said 9 days later:

    k, what exactly did you do to fix this?

  6. Avatar k said 9 days later:

    I’ve added:

    @html_options = {}

    to the method highlighted? in tab.rb (vendor/plugins/tabnav/lib/tabnav/tab.rb)

  7. Avatar Larry said 16 days later:

    Hi,

    I’m a several-year Java guy who just got exposed to RoR and LOVE it. I have implemented the shopping cart Depot Application in the Rails 1.2 book. I use RadRails for my IDE on Windows XP.

    Your tabnav plugin appeared in the RadRails Rails Plugins listbox. I selected ‘Go’ and hit ‘Install’ and it hung out for a few seconds and then ended – with no feedback. That’s not too unusual, so I went poking around the \vendor\plugins directory but could not find it.

    So I came to your site and found that tabnav had been updated to work on Rails 1.2. Great! I copied your instructions above (ruby script/plugin install svn://svn.seesaw.it/tabnav/trunk), fired up a DOS box, went to the root directory of my project, pasted the command, hit ‘Return’... and the same thing (or non-thing, as it were) happened. A few-seconds delay followed by no feedback and no trace of the plugin.

    I apologize if I am doing something stupid. If you could let me know what I did wrong I (and maybe other newbies) would appreciate it.

    Thanks a lot, Larry

  8. Avatar Larry said 16 days later:

    Hello again,

    Well, it turns out I did do something stupid. Or maybe just newbie-ish to be a little more fair and less harsh.

    Anyway, in the interest of helping other newbies: You need to have Subversion installed on your computer in order to install plugins.

    See http://wiki.rubyonrails.org/rails/pages/Plugins for more details.

    Thanks,
    Larry

  9. Avatar Jens said 22 days later:

    Hi,

    as far as I understand these tabs are designed to call different controller methods, ie. require reloads. Right?

    Is it possible to use this class to create a single-page tabbed navigation using DHTML/CSS? I would like to seperate my user profiles pages (and various data entering / signup tasks) into tabs and/or “wizard style” “next/previous page” interfaces, but keep a single form and single submit button for saving.

    Thanks!

  10. Avatar starburger said 32 days later:

    At first, thanks for tabnav – it seems to be the right thing for my current frontend project.

    But: When I have several tabbed screens in my app, I have to generate several corresponding xyz_tabnav.rb models.

    Now for each of these models there seems to be one template xyz_tybnav.rhtml which contains the style for the corresponding tabnav. Right?

    In my app ALL tabbed screens will have the SAME style (as I would assume for most apps in general). Does it mean that I have to maintain many of these style files for all the tabbed screens redundantly?

    Or can I consolidate the one style for all tabbed screens?

    Tahks,

    star

  11. Avatar Ary said 33 days later:

    Is tabnav released under the MIT license?

  12. Avatar Mort said 42 days later:

    Do you know if I can use tabnav and ajax scaffold at the same time? I am using AS already and would like to use tabnav and I wondered if there would be a conflict.

    Thanks.

  13. Avatar Mort said 42 days later:

    Tried it myself and it does work with ActiveScaffold – although not sure about the default color schemes. It’s actually a bit easier to with AS (at least to write the initial test app) because you don’t need anything except the layouts (eg no index.rhtml).

  14. Avatar Eric said 46 days later:

    I’m using the trunk version with Rails 1.2. In the development environment everything works fine. But in the production environment, once a tab is highlighted it stays highlighted, even as I look at other tabs.

    Interestingly, the posting at the top of this page would seem to say that a bug describing my situation was fixed over a month before I installed the Tabnav plugin (“i.e., Fixed a bug that cached evaluated Proc(s) after the first call in production environment.”)

    This happens for all my tabs—two normal ones and three that use procs for show_if, highlights_on, named, and links_to.

    Any help would be greatly appreciated.

    Thanks for Tabnav!

  15. Avatar Eric said 48 days later:

    I fixed the bug in my previous post. The fix requires one additional line of code, although with my comments and the surrounding white space, it’s currently at nine lines of code. The fix takes place in tabnav_helper.rb, and I’ll show the code starting at line 12, and my additions start at line 14 (blank line).

    
            tab = t.clone # I need this in order to avoid binding sharing issues    
    
            # The following line of code was added because without it tab           
            # is a shallow copy, and any alterations to tab's html_options          
            # affect the original's html_options also.  This led to a bug          
            # in which once a tab was shown as class active, it remained            
            # as class active.  This makes it a slightly deeper copy by             
            # duplicating the html_options.                                         
            tab.html_options(t.html_options.clone)
    
            tab.page=self
    
    
  16. Avatar Lee said 50 days later:

    Paolo,

    Thanks Brother! This is exactly what my app needed. So much so that all my new tabnav models have taken over my models directory. I made so many of them…. Could you suggest a direction I might go (as far as tweaking the code) so I can put all my tabnav models into a single file or a single sub-directory so I can declutter my models directory?

  17. Avatar Adam said 60 days later:

    LOVE IT! I’ll never have to write another tabbing system. Or if I do at least I’ll have a great example to work off of.

  18. Avatar Kelly said 64 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?

  19. Avatar nirmal said 103 days later:

    As a newbie i am impressed for the improvement of the plugin.

    thanks

  20. Avatar Derek said 110 days later:

    Hi,

    I’m trying to get some of my tabs right-aligned:

    add_tab do

    named 'Help'
    links_to :controller => 'admin'
    html_options[:style] = 'float: right;'

    end

    However, the right-aligned tabs appear underneath the main border, instead of on top. Anyone any ideas on how to fix this?

    Derek.

  21. Avatar racorbel1@free.fr said 118 days later:

    Hi Ihave a problem with tabnav and :confirm in a view in a tab_nav, dialogbox confirm never appears

    view link etc, :action=> ‘destroy’, :confirm => ‘Are you sure’

    Thanks

  22. Avatar Al said 123 days later:

    I too had a problem with svn, so I manually installed the plugin by placing the plugin directory to vendor. Is that the right thing to do?

    Running the init.rb lead to an error too, perhaps because I’m using instantrails.

    Then I tried to generate tabnav… there an error but somehow points to the files and directory of acts_as_paranoid-1.1.4. I really don’t know why.

    I removed the acts_as_paranoid-1.1.4 directory and tabnav generation seems to work…

    Does anyone experienced something similar, I think acts_as_paranoid plugin will be useful for me in the future.

  23. Avatar Craig said 139 days later:

    Is there any way to get a tabnav to link to a popup window instead of the main window?

    i.e. add_tab do named ‘ID Seq’ links_to :controller => ‘libraries’, :action => ‘id_seq’, :popup => [‘new_window’,’height=324,width=680’] end

    It still will only open in the main window

  24. Avatar Julien Marie said 151 days later:

    Hi ! I just wondered reading your doc on your plugin if it’s possible to replace text links with pictures ? thanks

  25. Avatar pantarhei said 153 days later:

    hello, i’m just migrating an existing app to rails 1.2.3.

    there’s in the main tab class usage of ‘subtabed ’. looks like this isn’t available anymore in the new version.

    am i missing something or where is my missunderstanding? or how to do subtabbing in the new version?

    regards

  26. Avatar Alger said 161 days later:

    CSS class information is lost when a tab is active. I changed the corresponding line in tabnav_helper.rb to

    if tab.highlighted?(params) tab.html_options[:class] += ’ active’ if ! tab.html_options[:class].nil? tab.html_options[:class] = ‘active’ if tab.html_options[:class].nil? end

    (Not nice, but does the trick.)

    BTW, I’m using Tabnav for almost all the menus in my project, not just tabbed ones. Just change the CSS to layout the ul as whatever you like.

  27. Avatar Irfan said 168 days later:

    Is there a way to use remote urls(ajax) in the the links_to proc ?

  28. Avatar Chris W said 175 days later:

    @Irfan: that’s a very good question, and one I’d like to echo.

    Currently I render a partial (which should include the tabbed navigation start and end tags) through the Ajax link_to_remote method. Can this be done with TabNav?

  29. Avatar larry said 183 days later:

    I notice that tab.rb contains highlighted? and visible? methods. How do you use these?
    For example, I have nested menus. Is there any way in the 2nd-level menu to specify a show_if { ... } condition for a tab in the 1st-level menu being visible? or highlighted??

  30. Avatar peter said 195 days later:

    how can i force the tabs to reload? it seems that the tabs are still caching their parameters in production mode after the first call. I was trying to use tabnav and globalize. in dev modeeverything as expects: tabs title and name are translated while they arent´t in production mode. Any idea?

  31. Avatar sgudibanda@gmail said 200 days later:

    Hi,

    I am using this tabnav to use it in view form:

    SetA SetB SetC A1) A2) A3)_

    A1, A2 and A3 are questions belonging to model setA. By default: SetA should be highlighted and the Questions in SetA should be displayed as content. SetA has a model. And when user navigates to other tabs, question related to that set get updated as the content. Is this possible?

    Regards, Sandeep G

  32. Avatar steve said 201 days later:

    This plugin works great, but for some RESTful URLs, I’m not sure of the best way to dynamically configure the link. Here’s the scenario:

    - Logged in users have access to a particular tab - If they click on that tab, the link is to user_categories_path(current_user)

    But… current_user is in the controller. How do you reach into the instance of the tabnav model to give it user information?

  33. Avatar Jonathan said 206 days later:

    Thanks for building this plugin.

    I need nav tabs that do ajax updates. That is, the content area is updated with ajax calls.

    If I revise your plugin to do this, I’ll let you know.

Comments are disabled


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